Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created May 24, 2017 05:38
Show Gist options
  • Save iporsut/828f09f2c890bd295963c567c9a82d75 to your computer and use it in GitHub Desktop.
Save iporsut/828f09f2c890bd295963c567c9a82d75 to your computer and use it in GitHub Desktop.
Refactor from P' Roof Go Presentation
package main
import (
"fmt"
"log"
"os"
"time"
)
func export(i int) {
filename := fmt.Sprintf("%d.test.txt", i)
fmt.Println("writing:", filename)
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
defer f.Close()
for i := 0; i < 10; i++ {
fmt.Println(filename, ":", i)
fmt.Fprintf(f, "%d ", i)
time.Sleep(time.Millisecond * 100)
}
}
func main() {
done := make(chan struct{}, 100)
for i := 0; i < 100; i++ {
go func(i int) {
export(i)
done <- struct{}{}
}(i)
}
<-done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment