Last active
September 11, 2020 14:32
-
-
Save gillesdemey/bdd9584bb944cc6dacbd156c77dd856c to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"golang.org/x/sync/errgroup" | |
"time" | |
) | |
func main() { | |
fmt.Println("Hello, world!") | |
eg := new(errgroup.Group) | |
eg.Go(asyncOne) | |
eg.Go(asyncTwo) | |
if err := eg.Wait(); err != nil { | |
fmt.Println("Encountered error:", err) | |
} | |
fmt.Println("Bye bye") | |
} | |
func asyncOne() error { | |
time.Sleep(3 * time.Second) | |
fmt.Println("async one") | |
return fmt.Errorf("Error happened") | |
} | |
func asyncTwo() error { | |
time.Sleep(1 * time.Second) | |
fmt.Println("async two") | |
return nil | |
} |
Author
gillesdemey
commented
Sep 11, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment