Created
August 17, 2018 21:58
-
-
Save sayden/d95f6d220234525f65fd0db672b4d41d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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