Skip to content

Instantly share code, notes, and snippets.

@ehfeng
Last active December 10, 2022 07:22
Show Gist options
  • Select an option

  • Save ehfeng/aca1c74502b801099ca0f7ba8f89b4cc to your computer and use it in GitHub Desktop.

Select an option

Save ehfeng/aca1c74502b801099ca0f7ba8f89b4cc to your computer and use it in GitHub Desktop.

Revisions

  1. ehfeng revised this gist Dec 10, 2022. No changes.
  2. ehfeng revised this gist Dec 10, 2022. No changes.
  3. ehfeng revised this gist Dec 10, 2022. No changes.
  4. ehfeng created this gist Dec 10, 2022.
    36 changes: 36 additions & 0 deletions channel_experiments.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    package main

    import "fmt"

    func f(x, y, z chan string) {
    defer close(x)
    a := make(chan bool)
    go func() {
    for i := 0; i < 3; i++ {
    x <- "hi"
    }
    a <- true
    }()

    <-a
    y <- "hello"
    z <- "hola"
    }

    func main() {
    x, y, z := make(chan string), make(chan string), make(chan string)
    go f(x, y, z)
    go func() {
    for m := range x {
    fmt.Println("m", m)
    }
    }()
    select {
    case b := <-y:
    fmt.Println("b", b)
    case c := <-z:
    fmt.Println("c", c)
    }

    fmt.Println("end")
    }