Skip to content

Instantly share code, notes, and snippets.

@azr
Forked from dpapathanasiou/reflexes.go
Created February 9, 2016 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azr/db05b6eb596604205d8b to your computer and use it in GitHub Desktop.
Save azr/db05b6eb596604205d8b to your computer and use it in GitHub Desktop.
Concurrency programming example: test user reflexes
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func main() {
goChan := make(chan time.Time)
go func() {
time.Sleep(time.Second * time.Duration(rand.Intn(3)))
fmt.Println("Go !")
goChan <- time.Now()
}()
bufio.NewReader(os.Stdin).ReadString('\n')
userTime := time.Now()
select {
case goTime := <-goChan:
fmt.Printf("%s\n", userTime.Sub(goTime))
default:
fmt.Println("Failed !")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment