Golang time.After() function example

package time

Golang time.After() function usage example

 package main

 import (
  "fmt"
  "time"
 )

 func main() {
  c := make(chan bool, 1)

  go func() {
 select {
 case m := <-c:
 // do something
 handle(m)
 case <-time.After(3 * time.Second):
 fmt.Println("timed out")
 }
  }()

  time.Sleep(5 * time.Second)
 }

 func handle(m bool) {}

Play at : http://play.golang.org/p/mWtdvxppu_

Reference :

http://golang.org/pkg/time/#After

Advertisement