Skip to content

Instantly share code, notes, and snippets.

@tranphuoctien
Created September 10, 2021 00:52
Show Gist options
  • Save tranphuoctien/9f3c85111b0e52158091d8683248e582 to your computer and use it in GitHub Desktop.
Save tranphuoctien/9f3c85111b0e52158091d8683248e582 to your computer and use it in GitHub Desktop.
Promise in golang
var userDetails *user.Details
var userCards []payment.Card
var userPurchases []shop.Purchase
errGroup, groupCtx := errgroup.WithContext(ctx)
errGroup.Go(func() error {
var err error
userDetails, err = user.FindDetailsByID(groupCtx, userID)
return err
})
errGroup.Go(func() error {
var err error
userCards, err = payment.FindCardsByUserID(groupCtx, userID)
return err
})
errGroup.Go(func() error {
var err error
userPurchases, err = shop.FindPurchasesByUserID(groupCtx, userID)
return err
})
err := errGroup.Wait()
if err != nil {
// ... handle the error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment