Created
May 24, 2017 05:38
-
-
Save iporsut/828f09f2c890bd295963c567c9a82d75 to your computer and use it in GitHub Desktop.
Refactor from P' Roof Go Presentation
This file contains hidden or 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" | |
"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