transdep/tools/timeout.go
2018-01-23 21:25:00 +01:00

20 lines
462 B
Go

package tools
import (
"time"
)
const DEFAULT_TIMEOUT_DURATION = 20 * time.Second
// Timeout waits for "dur" delay to expire, and then writes in "c"
func Timeout(dur time.Duration, c chan<- bool) {
time.Sleep(dur)
c <- true
}
// StartTimeout initiates a goroutine that will write a boolean into the returned channel after the "dur" delay expired.
func StartTimeout(dur time.Duration) <-chan bool {
c := make(chan bool, 1)
go Timeout(dur, c)
return c
}