Skip to content

Instantly share code, notes, and snippets.

@trafficone
Created February 15, 2022 08:10
Show Gist options
  • Save trafficone/565bd2e55f1da0b9b54fcebca1651b33 to your computer and use it in GitHub Desktop.
Save trafficone/565bd2e55f1da0b9b54fcebca1651b33 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
// FizzBuzz implemented using time and go's select
// At 15ms, fizz, buzz, and boom all trigger, so select will go through them at random (until it gets to boom)
func main() {
fizz := time.Tick(3 * time.Millisecond)
buzz := time.Tick(5 * time.Millisecond)
boom := time.Tick(15 * time.Millisecond)
for i:=1;true;i++{
time.Sleep(1 * time.Millisecond)
select {
case <-boom:
fmt.Println("BOOM!")
return
case <-fizz:
fmt.Println("fizz.")
case <-buzz:
fmt.Println("buzz.")
default:
fmt.Println(i)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment