Skip to content

Instantly share code, notes, and snippets.

@balaa
Forked from t9md/go-tour-select.go
Created January 20, 2020 09:54
Show Gist options
  • Select an option

  • Save balaa/d6ec2f9a948bbe015048d30caf5c06c9 to your computer and use it in GitHub Desktop.

Select an option

Save balaa/d6ec2f9a948bbe015048d30caf5c06c9 to your computer and use it in GitHub Desktop.

Revisions

  1. @t9md t9md revised this gist Feb 5, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    package main

    /*
  2. @t9md t9md revised this gist Feb 5, 2015. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ func fibonacci(out, quit chan int) {
    select {
    case out <- x: // if out-ch is available for write(means out-ch's buffer is not full), send next fib number x
    x, y = y, x+y
    case <-quit: // if some data come to quit-ch, then break inifinite loop by return.
    case <-quit: // if any data come to quit-ch, then break inifinite loop by return.
    fmt.Println("quit")
    return
    }
    @@ -53,8 +53,8 @@ func main() {
    // Create anonymous func() and immediately execute as goroutine.
    // This function iterate 10 times of (read fib number from out-ch and Println).
    // After that, send `0` to quit-ch to notify other fibonacci() to break inifinit loop.
    // func() is closure referencing `out`, `quit` channel variable which originaly
    // created in enclosing main() function
    // func() is closure referencing outer `out`, `quit` channel variable which originaly
    // created in enclosing main() function.
    go func() {
    for i := 0; i < 10; i++ {
    fmt.Println(<-out) // pop data from out-ch 10 times
    @@ -82,20 +82,20 @@ func main() {
    numbers, unless some data is sent to channel 'quit'
    Communication channel(out, quit) is passed by arguments.
    +-fibonaci(out, quit) in main()--+ +--- go func() as goroutine ------+
    | x, y := 0, 1 | | |
    | for { | | |
    | select { | | |
    | case out <- x: | ------------ | for i := 0; i < 10; i++ { | *1
    | x, y = x, x+y x == out<int> ====> fmt.Println(<-out) //(*1) | groutine func() feel 10 times of data from out-ch
    | | ------------ | } | as sufficient.
    +-fibonacci(out, quit) in main()--+ +--- go func() as goroutine ------+
    | | | |
    | x, y := 0, 1 | | |
    | for { | | |
    | select { | ------------ | for i := 0; i < 10; i++ { | *1
    | case out <- x: x == out<int> ====> fmt.Println(<-out) //(*1) | groutine func() feel 10 times of data from out-ch
    | x, y = x, x+y | ------------ | } | as sufficient.
    | | | | after for loop finish...
    | | ------------ | |
    | case <- quit: <=== quit<int> <== 0 quit <- 0 (*2) | *2
    | fmt.Println("quit) | ------------ | | Send 0 to quit-ch for the purpose of break
    | return | | | inifinite loop of fibonacci().
    | } | | |
    | } | | |
    | case <- quit: <=== quit<int> <== 0 quit <- 0 (*2) | *2
    | fmt.Println("quit") | ------------ | | Send 0 to quit-ch for the purpose of stopping
    | return | | | inifinite loop of fibonacci().
    | } | | |
    | } | | |
    +--------------------------------+ +---------------------------------+
    */

  3. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 46 additions and 47 deletions.
    93 changes: 46 additions & 47 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -27,27 +27,27 @@ func fibonacci(out, quit chan int) {

    func main() {
    /*
    main() start
    +-- main() --+
    | |
    | |
    | |
    | |
    +------------+
    main() start
    +-- main() --+
    | |
    | |
    | |
    | |
    +------------+
    */
    out := make(chan int)
    quit := make(chan int)
    /*
    two channel (out, quit) created
    +-- main() --+
    | |--------------
    | | out<int>
    | |--------------
    | |--------------
    | | quit<int>
    | |--------------
    +------------+
    two channel (out, quit) created
    +-- main() --+
    | |--------------
    | | out<int>
    | |--------------
    | |--------------
    | | quit<int>
    | |--------------
    +------------+
    */

    // Create anonymous func() and immediately execute as goroutine.
    @@ -57,47 +57,46 @@ func main() {
    // created in enclosing main() function
    go func() {
    for i := 0; i < 10; i++ {
    fmt.Println(<-out) // pop data from chan-out 10 times
    fmt.Println(<-out) // pop data from out-ch 10 times
    }
    quit <- 0 // then send 0 to quit
    }()
    /*
    +--- main () -------------+ +---- go func() as goroutine ----------+
    | | | |
    | | ------------ | for i := 0; i < 10; i++ { | *1
    | | out<int> ====> fmt.Println(<-out) //(*1) | Blocking here for now.
    | | ------------ | } | since no data come from out-ch.
    | | | | First data will come after fibonacci() start
    | | ------------ | |
    | | quit<int> <== 0 quit <- 0 | *2
    | | ------------ | | Send 0 to quit-ch for the purpose of break
    | | | | inifinite loop of fibonacci().
    +-------------------------+ +--------------------------------------+
    +--- main () -------------+ +---- go func() as goroutine ----------+
    | | | |
    | | ------------ | for i := 0; i < 10; i++ { | *1
    | | out<int> ====> fmt.Println(<-out) //(*1) | Blocking here for now.
    | | ------------ | } | since no data come from out-ch.
    | | | | First data will come after fibonacci() start
    | | ------------ | |
    | | quit<int> <== 0 quit <- 0 | *2
    | | ------------ | | Send 0 to quit-ch to break
    | | | | inifinite loop of fibonacci().
    +-------------------------+ +--------------------------------------+
    */

    fibonacci(out, quit)
    /*
    Start fibonacci number generater fibonacci(), this fibonacci() function inifinitely generate fibonacci
    communication channel(out, quit) is passed by arguments.
    numbers, unless some data is sent to channel 'quit'
    Start fibonacci number generater fibonacci(), this fibonacci() function inifinitely generate fibonacci
    numbers, unless some data is sent to channel 'quit'
    Communication channel(out, quit) is passed by arguments.
    +-fibonaci(out, quit) in main()--+ +--- go func() as goroutine ------+
    | x, y := 0, 1 | | |
    | for { | | |
    | select { | | |
    | case out <- x: | ------------ | for i := 0; i < 10; i++ { | *1
    | x, y = x, x+y x == out<int> ====> fmt.Println(<-out) //(*1) | groutine func() feel 10 times of data from out-ch
    | | ------------ | } | as sufficient.
    | | | | after for loop finish...
    | | ------------ | |
    | case <- quit: <=== quit<int> <== 0 quit <- 0 (*2) | *2
    | fmt.Println("quit) | ------------ | | Send 0 to quit-ch for the purpose of break
    | return | | | inifinite loop of fibonacci().
    | } | | |
    | } | | |
    +--------------------------------+ +---------------------------------+
    +-fibonaci(out, quit) in main()--+ +--- go func() as goroutine ------+
    | x, y := 0, 1 | | |
    | for { | | |
    | select { | | |
    | case out <- x: | ------------ | for i := 0; i < 10; i++ { | *1
    | x, y = x, x+y x == out<int> ====> fmt.Println(<-out) //(*1) | groutine func() feel 10 times of data from out-ch
    | | ------------ | } | as sufficient.
    | | | | after for loop finish...
    | | ------------ | |
    | case <- quit: <=== quit<int> <== 0 quit <- 0 (*2) | *2
    | fmt.Println("quit) | ------------ | | Send 0 to quit-ch for the purpose of break
    | return | | | inifinite loop of fibonacci().
    | } | | |
    | } | | |
    +--------------------------------+ +---------------------------------+
    */

    }
  4. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    package main

    /*
  5. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 46 additions and 45 deletions.
    91 changes: 46 additions & 45 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -26,27 +26,27 @@ func fibonacci(out, quit chan int) {

    func main() {
    /*
    main() start
    +-- main() --+
    | |
    | |
    | |
    | |
    +------------+
    main() start
    +-- main() --+
    | |
    | |
    | |
    | |
    +------------+
    */
    out := make(chan int)
    quit := make(chan int)
    /*
    two channel (out, quit) created
    +-- main() --+
    | |--------------
    | | out<int>
    | |--------------
    | |--------------
    | | quit<int>
    | |--------------
    +------------+
    two channel (out, quit) created
    +-- main() --+
    | |--------------
    | | out<int>
    | |--------------
    | |--------------
    | | quit<int>
    | |--------------
    +------------+
    */

    // Create anonymous func() and immediately execute as goroutine.
    @@ -62,40 +62,41 @@ func main() {
    }()
    /*
    +--- main () -------------+ +---- go func() as goroutine ----------+
    | | | |
    | | ------------ | for i := 0; i < 10; i++ { | *1
    | | out<int> ====> fmt.Println(<-out) //(*1) | Blocking here for now.
    | | ------------ | } | since no data come from out-ch.
    | | | | First data will come after fibonacci() start
    | | ------------ | |
    | | quit<int> <== 0 quit <- 0 | *2
    | | ------------ | | Send 0 to quit-ch for the purpose of break
    | | | | inifinite loop of fibonacci().
    +-------------------------+ +--------------------------------------+
    +--- main () -------------+ +---- go func() as goroutine ----------+
    | | | |
    | | ------------ | for i := 0; i < 10; i++ { | *1
    | | out<int> ====> fmt.Println(<-out) //(*1) | Blocking here for now.
    | | ------------ | } | since no data come from out-ch.
    | | | | First data will come after fibonacci() start
    | | ------------ | |
    | | quit<int> <== 0 quit <- 0 | *2
    | | ------------ | | Send 0 to quit-ch for the purpose of break
    | | | | inifinite loop of fibonacci().
    +-------------------------+ +--------------------------------------+
    */

    fibonacci(out, quit) // communication channel is passed as function arguments.
    fibonacci(out, quit)
    /*
    start fibonacci number generater fibonacci(), this fibonacci() function inifinitely generate fibonacci
    numbers, unless some data is sent to channel 'quit'
    Start fibonacci number generater fibonacci(), this fibonacci() function inifinitely generate fibonacci
    communication channel(out, quit) is passed by arguments.
    numbers, unless some data is sent to channel 'quit'
    +-fibonaci(out, quit) in main()--+ +--- go func() as goroutine ------+
    | x, y := 0, 1 | | |
    | for { | | |
    | select { | | |
    | case out <- x: | ------------ | for i := 0; i < 10; i++ { | *1
    | x, y = x, x+y x == out<int> ====> fmt.Println(<-out) //(*1) | groutine func() feel 10 times of data from out-ch
    | | ------------ | } | as sufficient.
    | | | | after for loop finish...
    | | ------------ | |
    | case <- quit: <=== quit<int> <== 0 quit <- 0 (*2) | *2
    | fmt.Println("quit) | ------------ | | Send 0 to quit-ch for the purpose of break
    | return | | | inifinite loop of fibonacci().
    | } | | |
    | } | | |
    +--------------------------------+ +---------------------------------+
    +-fibonaci(out, quit) in main()--+ +--- go func() as goroutine ------+
    | x, y := 0, 1 | | |
    | for { | | |
    | select { | | |
    | case out <- x: | ------------ | for i := 0; i < 10; i++ { | *1
    | x, y = x, x+y x == out<int> ====> fmt.Println(<-out) //(*1) | groutine func() feel 10 times of data from out-ch
    | | ------------ | } | as sufficient.
    | | | | after for loop finish...
    | | ------------ | |
    | case <- quit: <=== quit<int> <== 0 quit <- 0 (*2) | *2
    | fmt.Println("quit) | ------------ | | Send 0 to quit-ch for the purpose of break
    | return | | | inifinite loop of fibonacci().
    | } | | |
    | } | | |
    +--------------------------------+ +---------------------------------+
    */

    }
  6. @t9md t9md revised this gist Feb 4, 2015. No changes.
  7. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    package main

    /*
  8. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -59,7 +59,6 @@ func main() {
    for i := 0; i < 10; i++ {
    fmt.Println(<-out) // pop data from chan-out 10 times
    }
    fmt.Println(str)
    quit <- 0 // then send 0 to quit
    }()
    /*
  9. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 32 additions and 28 deletions.
    60 changes: 32 additions & 28 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@


    package main

    /*
    @@ -54,46 +53,51 @@ func main() {
    // Create anonymous func() and immediately execute as goroutine.
    // This function iterate 10 times of (read fib number from out-ch and Println).
    // After that, send `0` to quit-ch to notify other fibonacci() to break inifinit loop.
    // func() is closure referencing `out`, `quit` channel variable which originaly
    // created in enclosing main() function
    go func() {
    for i := 0; i < 10; i++ {
    fmt.Println(<-out) // pop data from chan-out 10 times
    }
    fmt.Println(str)
    quit <- 0 // then send 0 to quit
    }()
    /*
    +--- main () -------------+ +--- goroutine: func() ---------------+
    | | | |
    | | ------------ | for i := 0; i < 10; i++ { | *1
    | | out<int> ====> fmt.Println(<-out) //(*1) | Blocking here for now.
    | | ------------ | } | since no data come from out-ch.
    | | | | First data will come after fibonacci() start
    | | ------------ | |
    | | quit<int> <== 0 quit <- 0 | *2
    | | ------------ | | Send 0 to quit-ch for the purpose of break
    | | | | inifinit loop of fibonacci()
    | | | |
    +-------------------------+ +--------------------------------------+
    +--- main () -------------+ +---- go func() as goroutine ----------+
    | | | |
    | | ------------ | for i := 0; i < 10; i++ { | *1
    | | out<int> ====> fmt.Println(<-out) //(*1) | Blocking here for now.
    | | ------------ | } | since no data come from out-ch.
    | | | | First data will come after fibonacci() start
    | | ------------ | |
    | | quit<int> <== 0 quit <- 0 | *2
    | | ------------ | | Send 0 to quit-ch for the purpose of break
    | | | | inifinite loop of fibonacci().
    +-------------------------+ +--------------------------------------+
    */

    fibonacci(out, quit)
    fibonacci(out, quit) // communication channel is passed as function arguments.
    /*
    fibonacci() start, this fibonacci() function inifinitely generate fibonacci
    numbers, unless some data is sent to channel 'quit'
    start fibonacci number generater fibonacci(), this fibonacci() function inifinitely generate fibonacci
    numbers, unless some data is sent to channel 'quit'
    +---anonymous func() in main()--+ +-- fibonacci()---------+
    | for i := 0; i < 10; i++ { |------------------- | select { |
    | t.Println(<-out) <====== out<int> <== x | case out <- x: |
    | } |------------------- | x, y = x, x+y |
    | | | |
    | | | |
    | |------------------- | |
    | quit <- 0 0 =======> quit<int> =======> case <- quit: |
    | |------------------- | fmt.Println("quit) |
    | | | return |
    | | | } |
    +-------------------------------+ +-----------------------+
    +-fibonaci(out, quit) in main()--+ +--- go func() as goroutine ------+
    | x, y := 0, 1 | | |
    | for { | | |
    | select { | | |
    | case out <- x: | ------------ | for i := 0; i < 10; i++ { | *1
    | x, y = x, x+y x == out<int> ====> fmt.Println(<-out) //(*1) | groutine func() feel 10 times of data from out-ch
    | | ------------ | } | as sufficient.
    | | | | after for loop finish...
    | | ------------ | |
    | case <- quit: <=== quit<int> <== 0 quit <- 0 (*2) | *2
    | fmt.Println("quit) | ------------ | | Send 0 to quit-ch for the purpose of break
    | return | | | inifinite loop of fibonacci().
    | } | | |
    | } | | |
    +--------------------------------+ +---------------------------------+
    */

    }
  10. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@


    package main

    /*
  11. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 18 additions and 16 deletions.
    34 changes: 18 additions & 16 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    package main

    /*
    @@ -49,29 +50,30 @@ func main() {
    +------------+
    */

    // Create anonymous func() and immediately call
    // this iterate 10 times of (read fib number(int) from out-ch and Println).
    // After that, send `0` to quit-ch to notify other goroutine(=fibonacci() ) to break inifinit loop.
    // Create anonymous func() and immediately execute as goroutine.
    // This function iterate 10 times of (read fib number from out-ch and Println).
    // After that, send `0` to quit-ch to notify other fibonacci() to break inifinit loop.
    go func() {
    for i := 0; i < 10; i++ {
    fmt.Println(<-out) // pop data from chan-c 10 times
    fmt.Println(<-out) // pop data from chan-out 10 times
    }
    quit <- 0 // then send 0 to quit
    }()
    /*
    +---anonymous func() in main()--+
    | for i := 0; i < 10; i++ { |------------- !! (*1)
    | t.Println(<-out) //(*1) <== out<int> !! Blocking here for now.
    | |------------- !! since no data come from `out` channel.
    | | !! First data will come after fibonacci() start
    | } |
    | |-------------
    | quit <- 0 0 =======> quit<int>
    | |-------------
    | |
    | |
    +-------------------------------+
    +--- main () -------------+ +--- goroutine: func() ---------------+
    | | | |
    | | ------------ | for i := 0; i < 10; i++ { | *1
    | | out<int> ====> fmt.Println(<-out) //(*1) | Blocking here for now.
    | | ------------ | } | since no data come from out-ch.
    | | | | First data will come after fibonacci() start
    | | ------------ | |
    | | quit<int> <== 0 quit <- 0 | *2
    | | ------------ | | Send 0 to quit-ch for the purpose of break
    | | | | inifinit loop of fibonacci()
    | | | |
    +-------------------------+ +--------------------------------------+
    */

    fibonacci(out, quit)
  12. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ func fibonacci(out, quit chan int) {
    x, y := 0, 1
    for {
    select {
    case out <- x: // if out-ch is available for write(mean empty), send next fib number x
    case out <- x: // if out-ch is available for write(means out-ch's buffer is not full), send next fib number x
    x, y = y, x+y
    case <-quit: // if some data come to quit-ch, then break inifinite loop by return.
    fmt.Println("quit")
  13. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -15,9 +15,9 @@ func fibonacci(out, quit chan int) {
    x, y := 0, 1
    for {
    select {
    case out <- x: // if x is available for write(mean empty), send next fib number x to out-ch
    case out <- x: // if out-ch is available for write(mean empty), send next fib number x
    x, y = y, x+y
    case <-quit: // if some data is stocked in quit-ch, then break inifinite loop by return.
    case <-quit: // if some data come to quit-ch, then break inifinite loop by return.
    fmt.Println("quit")
    return
    }
  14. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -65,7 +65,7 @@ func main() {
    | t.Println(<-out) //(*1) <== out<int> !! Blocking here for now.
    | |------------- !! since no data come from `out` channel.
    | | !! First data will come after fibonacci() start
    | } |
    | } |
    | |-------------
    | quit <- 0 0 =======> quit<int>
    | |-------------
  15. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -65,7 +65,7 @@ func main() {
    | t.Println(<-out) //(*1) <== out<int> !! Blocking here for now.
    | |------------- !! since no data come from `out` channel.
    | | !! First data will come after fibonacci() start
    | } | !!
    | } |
    | |-------------
    | quit <- 0 0 =======> quit<int>
    | |-------------
    @@ -77,7 +77,7 @@ func main() {
    fibonacci(out, quit)
    /*
    fibonacci() start, this fibonacci() function inifinitely generate fibonacci
    numbers, unless some data is send to channel 'quit'
    numbers, unless some data is sent to channel 'quit'
    +---anonymous func() in main()--+ +-- fibonacci()---------+
    | for i := 0; i < 10; i++ { |------------------- | select { |
  16. @t9md t9md revised this gist Feb 4, 2015. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -79,18 +79,18 @@ func main() {
    fibonacci() start, this fibonacci() function inifinitely generate fibonacci
    numbers, unless some data is send to channel 'quit'
    +---anonymous func() in main()--+ +-- fibonacci()---------+
    | for i := 0; i < 10; i++ { |------------------- | select { |
    | t.Println(<-out) <====== out<int> <== x | case out <- x: |
    | } |------------------- | x, y = x, x+y |
    | | | |
    | | | |
    | |------------------- | |
    | quit <- 0 0 =======> quit<int> =======> case <- quit: |
    | |------------------- | fmt.Println("quit) |
    | | | return |
    | | | } |
    +-------------------------------+ +-----------------------+
    +---anonymous func() in main()--+ +-- fibonacci()---------+
    | for i := 0; i < 10; i++ { |------------------- | select { |
    | t.Println(<-out) <====== out<int> <== x | case out <- x: |
    | } |------------------- | x, y = x, x+y |
    | | | |
    | | | |
    | |------------------- | |
    | quit <- 0 0 =======> quit<int> =======> case <- quit: |
    | |------------------- | fmt.Println("quit) |
    | | | return |
    | | | } |
    +-------------------------------+ +-----------------------+
    */

    }
    }
  17. @t9md t9md created this gist Feb 4, 2015.
    96 changes: 96 additions & 0 deletions go-tour-select.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,96 @@
    package main

    /*
    Channel and select {} illustrated by t9md
    ===========================================================
    sample program to understand goroutine communication via channel.
    based on go-tour's example
    https://tour.golang.org/concurrency/5
    */

    import "fmt"

    func fibonacci(out, quit chan int) {
    x, y := 0, 1
    for {
    select {
    case out <- x: // if x is available for write(mean empty), send next fib number x to out-ch
    x, y = y, x+y
    case <-quit: // if some data is stocked in quit-ch, then break inifinite loop by return.
    fmt.Println("quit")
    return
    }
    }
    }

    func main() {
    /*
    main() start
    +-- main() --+
    | |
    | |
    | |
    | |
    +------------+
    */
    out := make(chan int)
    quit := make(chan int)
    /*
    two channel (out, quit) created
    +-- main() --+
    | |--------------
    | | out<int>
    | |--------------
    | |--------------
    | | quit<int>
    | |--------------
    +------------+
    */

    // Create anonymous func() and immediately call
    // this iterate 10 times of (read fib number(int) from out-ch and Println).
    // After that, send `0` to quit-ch to notify other goroutine(=fibonacci() ) to break inifinit loop.
    go func() {
    for i := 0; i < 10; i++ {
    fmt.Println(<-out) // pop data from chan-c 10 times
    }
    quit <- 0 // then send 0 to quit
    }()
    /*
    +---anonymous func() in main()--+
    | for i := 0; i < 10; i++ { |------------- !! (*1)
    | t.Println(<-out) //(*1) <== out<int> !! Blocking here for now.
    | |------------- !! since no data come from `out` channel.
    | | !! First data will come after fibonacci() start
    | } | !!
    | |-------------
    | quit <- 0 0 =======> quit<int>
    | |-------------
    | |
    | |
    +-------------------------------+
    */

    fibonacci(out, quit)
    /*
    fibonacci() start, this fibonacci() function inifinitely generate fibonacci
    numbers, unless some data is send to channel 'quit'
    +---anonymous func() in main()--+ +-- fibonacci()---------+
    | for i := 0; i < 10; i++ { |------------------- | select { |
    | t.Println(<-out) <====== out<int> <== x | case out <- x: |
    | } |------------------- | x, y = x, x+y |
    | | | |
    | | | |
    | |------------------- | |
    | quit <- 0 0 =======> quit<int> =======> case <- quit: |
    | |------------------- | fmt.Println("quit) |
    | | | return |
    | | | } |
    +-------------------------------+ +-----------------------+
    */

    }