Skip to content

Instantly share code, notes, and snippets.

@BruceWangNo1
Created March 24, 2019 12:47
Show Gist options
  • Save BruceWangNo1/159cb4f7b8beb6f587a66e199f9fd319 to your computer and use it in GitHub Desktop.
Save BruceWangNo1/159cb4f7b8beb6f587a66e199f9fd319 to your computer and use it in GitHub Desktop.
code for the Medium Post: Implementation Details of Goroutine
package main
import (
"fmt"
"time"
)
func printNumber(from, to int, c chan int) {
for x := from; x <= to; x++ {
fmt.Printf("%d\n", x)
time.Sleep(1 * time.Millisecond)
}
c <- 0
}
func main() {
c := make(chan int, 3)
go printNumber(1, 3, c)
go printNumber(4, 6, c)
_ = <- c
_ = <- c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment