Skip to content

Instantly share code, notes, and snippets.

@telless
Created May 22, 2017 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telless/48b9c5e66e21771643bf1636e3a24611 to your computer and use it in GitHub Desktop.
Save telless/48b9c5e66e21771643bf1636e3a24611 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"strconv"
"time"
)
func lPrint(ch chan string, delay time.Duration) {
for toPrint := range ch {
time.Sleep(delay)
fmt.Println(toPrint)
}
}
func main() {
ch := make(chan string, 100)
buf := bytes.Buffer{}
go lPrint(ch, 50*time.Millisecond)
for i := 1; i <= 100; i++ {
if i%3 == 0 {
buf.WriteString("Fizz")
}
if i%5 == 0 {
buf.WriteString("Buzz")
}
if buf.Len() == 0 {
buf.WriteString(strconv.Itoa(i))
}
ch <- buf.String()
buf.Reset()
}
close(ch)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment