Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created March 30, 2017 11:16
Show Gist options
  • Save alextanhongpin/89cc1f868ff76dedae5137c9c7c99224 to your computer and use it in GitHub Desktop.
Save alextanhongpin/89cc1f868ff76dedae5137c9c7c99224 to your computer and use it in GitHub Desktop.
Blocking example using golang channels
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