Created
March 30, 2017 11:16
-
-
Save alextanhongpin/89cc1f868ff76dedae5137c9c7c99224 to your computer and use it in GitHub Desktop.
Blocking example using golang channels
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() { | |
c := make(chan bool) | |
start := time.Now() | |
go func() { | |
time.Sleep(2 * time.Second) | |
close(c) | |
}() | |
<-c | |
fmt.Printf("%.2f seconds passed", time.Now().Sub(start).Seconds()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment