-
-
Save emretanriverdi/a805fa90e991f19cfec99221cdc80768 to your computer and use it in GitHub Desktop.
goroutine-with-waitgroup.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 upsert(user User) { | |
var wg sync.WaitGroup | |
wg.Add(1) | |
go upsertToPostgres(user, &wg) | |
upsertToCouchbase(user, "key") | |
wg.Wait() | |
} | |
func upsertToPostgres(user User, wg *sync.WaitGroup) { | |
fmt.Println("# upserting userId to two tables in Postgres") | |
time.Sleep(20 * time.Millisecond) | |
fmt.Println("# upserting userName to one table in Postgres") | |
time.Sleep(10 * time.Millisecond) | |
wg.Done() | |
} | |
func upsertToCouchbase(user User, key string) { | |
fmt.Println("# upserting to Couchbase") | |
time.Sleep(5 * time.Millisecond) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment