Created
May 3, 2018 16:06
-
-
Save radiofreejohn/7c502a4d41cd2e765980ddcf249c4b78 to your computer and use it in GitHub Desktop.
adding callback hell to go, why not?
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" | |
"io/ioutil" | |
"log" | |
"os" | |
"sync" | |
) | |
func openAsync(fileName string, callback func([]byte, error)) { | |
callback(ioutil.ReadFile(fileName)) | |
} | |
func printContents(contents []byte, err error) { | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%s", contents) | |
} | |
func main() { | |
var wg sync.WaitGroup | |
arg := os.Args[1] | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
openAsync(arg, printContents) | |
}() | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment