Skip to content

Instantly share code, notes, and snippets.

@emretanriverdi
Created January 17, 2021 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emretanriverdi/a805fa90e991f19cfec99221cdc80768 to your computer and use it in GitHub Desktop.
Save emretanriverdi/a805fa90e991f19cfec99221cdc80768 to your computer and use it in GitHub Desktop.
goroutine-with-waitgroup.go
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