Created
September 10, 2021 00:52
-
-
Save tranphuoctien/9f3c85111b0e52158091d8683248e582 to your computer and use it in GitHub Desktop.
Promise in golang
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
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