Skip to content

Instantly share code, notes, and snippets.

@pbiernacki
Created August 12, 2016 12:15
Show Gist options
  • Save pbiernacki/5f8b07c385a076539459838e766d5006 to your computer and use it in GitHub Desktop.
Save pbiernacki/5f8b07c385a076539459838e766d5006 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
var end = make(chan struct{})
func tick(n int) {
ticker := time.NewTicker(3 * time.Second)
go func(n int) {
for {
select {
case <-ticker.C:
fmt.Printf("dupa%d\n", n)
case <-end:
ticker.Stop()
return
}
}
}(n)
}
func main() {
for i := 0; i < 10; i++ {
fmt.Printf("go tick(%d)\n", i)
go tick(i)
}
time.Sleep(30 * time.Second)
fmt.Println("closing...")
close(end)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment