transdep/tools/timeout.go

21 lines
462 B
Go
Raw Normal View History

2018-01-23 20:25:00 +00:00
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
}