Created
December 27, 2017 10:17
-
-
Save wilon/05d3990e02b6192017858c82dc5c084c to your computer and use it in GitHub Desktop.
test chan
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 ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
ch := make(chan int, 1) | |
go func() { | |
inV := 1 | |
for { | |
ch <- inV | |
fmt.Println(time.Now(), "...in", inV) | |
time.Sleep(1000 * time.Millisecond) | |
inV++ | |
} | |
}() | |
var outV int | |
for { | |
outV = <-ch | |
fmt.Println(time.Now(), "...out", outV) | |
time.Sleep(4000 * time.Millisecond) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment