Skip to content

Instantly share code, notes, and snippets.

@sayden
Created August 17, 2018 21:58
Show Gist options
  • Save sayden/d95f6d220234525f65fd0db672b4d41d to your computer and use it in GitHub Desktop.
Save sayden/d95f6d220234525f65fd0db672b4d41d to your computer and use it in GitHub Desktop.
package main
import (
"github.com/thehivecorporation/log"
"math/rand"
"time"
)
func main() {
ch := make(chan struct{})
waitduration := 500 * time.Millisecond
timer := time.NewTimer(waitduration)
go func() {
rand.Seed(33)
for {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
ch <- struct{}{}
}
}()
for {
select {
case _ = <-ch:
log.Info("Value received")
case <-timer.C:
log.Info("Too much time waited")
}
timer.Reset(waitduration)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment