Created
February 15, 2022 08:10
-
-
Save trafficone/565bd2e55f1da0b9b54fcebca1651b33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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