Created
May 22, 2017 09:18
-
-
Save telless/48b9c5e66e21771643bf1636e3a24611 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"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