Skip to content

Instantly share code, notes, and snippets.

@hosszukalman
Created February 1, 2018 15:43
Show Gist options
  • Save hosszukalman/940f757849e09d1048584d49a26b8f99 to your computer and use it in GitHub Desktop.
Save hosszukalman/940f757849e09d1048584d49a26b8f99 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Hello, playground")
start := time.Now()
ok := make(chan bool)
go func() {
time.Sleep(time.Second * 5)
ok <- true
}()
//time.Sleep(time.Second * 2)
time.AfterFunc(time.Second*2, func() {
ok <- false
})
if <-ok {
fmt.Println("ok")
fmt.Printf("time: %s", time.Since(start))
return
}
fmt.Println("not ok")
fmt.Printf("time: %s", time.Since(start))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment