Skip to content

Instantly share code, notes, and snippets.

@cloudaice
Created August 1, 2013 13:48
Show Gist options
  • Save cloudaice/6131509 to your computer and use it in GitHub Desktop.
Save cloudaice/6131509 to your computer and use it in GitHub Desktop.

Revisions

  1. cloudaice created this gist Aug 1, 2013.
    27 changes: 27 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    package main

    import "fmt"
    import "time"
    import "runtime"

    func main(){
    runtime.GOMAXPROCS(8)
    channel := make(chan string)

    for i:=0; i<5; i++ {
    go func (id int) {
    for {
    time.Sleep(3)
    msg := <-channel
    fmt.Println(msg, id)
    }
    }(i)
    }

    ticker := time.NewTicker(time.Second)

    for t := range ticker.C {
    fmt.Println(t)
    channel <- "hello world"
    }
    }