diff --git a/00-notes.txt b/00-notes.txt new file mode 100644 index 0000000..81144f4 --- /dev/null +++ b/00-notes.txt @@ -0,0 +1,24 @@ += distribution +* leading blog posts + * a new kind of programming book + * minimize text, maximize examples + * focus on working programs + * syntax highlighting + * select, actors, threads, and event loops + * small go programming examples +* newsletter +* twitter +* stack overflow answers + += pricing +* high +* updates +* no drm +* offers of free books in comments + += source +* popular github libraries +* mailing list questions +* stack overflow questions +* handbook format +* rosetta stone diff --git a/37-concurrency.go b/37-concurrency.go new file mode 100644 index 0000000..6090f05 --- /dev/null +++ b/37-concurrency.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "time" + "math/rand" +) + +func f(n int) { + for i := 0; i < 10; i++ { + fmt.Println(n, ":", i) + time.Sleep(time.Millisecond * time.Duration(rand.Intn(150))) + } +} + +func main() { + for i := 0; i < 5; i++ { + f(i) + } + fmt.Println() + for i := 0; i < 5; i++ { + go f(i) + } + var input string + fmt.Scanln(&input) +} diff --git a/38-channels.go b/38-channels.go new file mode 100644 index 0000000..102c089 --- /dev/null +++ b/38-channels.go @@ -0,0 +1,10 @@ +package main + +import "fmt" + +func main() { + var messages chan string = make(chan string) + go func() { messages <- "ping"}() + msg := <- messages + fmt.Println(msg) +} diff --git a/39-buffering.go b/39-buffering.go new file mode 100644 index 0000000..a9c29e5 --- /dev/null +++ b/39-buffering.go @@ -0,0 +1,10 @@ +package main + +import "fmt" + +func main() { + var messages chan string = make(chan string, 1) + messages <- "ping" + msg := <- messages + fmt.Println(msg) +}