Skip to content

Instantly share code, notes, and snippets.

@radiofreejohn
Created May 3, 2018 16:06
Show Gist options
  • Save radiofreejohn/7c502a4d41cd2e765980ddcf249c4b78 to your computer and use it in GitHub Desktop.
Save radiofreejohn/7c502a4d41cd2e765980ddcf249c4b78 to your computer and use it in GitHub Desktop.
adding callback hell to go, why not?
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