Last active
April 15, 2021 12:58
-
-
Save emretanriverdi/2bc8e2e59fa77bb3d1bdead6949a6247 to your computer and use it in GitHub Desktop.
anonymous-function-goroutine-defer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func upsertAllUsersToPostgres(users []User) { | |
var wg sync.WaitGroup | |
wg.Add(len(users)) | |
for _, user := range users { | |
go func(user User, wg *sync.WaitGroup) { | |
defer wg.Done() | |
repository.UpsertToPostgres(user) | |
}(user, &wg) | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment