Skip to content

Instantly share code, notes, and snippets.

@xiaq
Created April 4, 2016 03:34
Show Gist options
  • Select an option

  • Save xiaq/fccdb5ae8807281b595e7c9fd64dd70e to your computer and use it in GitHub Desktop.

Select an option

Save xiaq/fccdb5ae8807281b595e7c9fd64dd70e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"os"
)
func e(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
f, err := os.OpenFile("./a", os.O_RDWR|os.O_CREATE, 0644)
e(err)
ch := make(chan bool)
go func() {
_, err := f.WriteString("233")
e(err)
ch <- true
}()
go func() {
var buf [3]byte
n, err := f.Read(buf[:])
e(err)
fmt.Println(string(buf[:n]))
ch <- true
}()
<-ch
<-ch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment