fixes to linkInterface.handler()

This commit is contained in:
Arceliar 2019-02-26 21:07:56 -06:00
parent def4fb3587
commit 2569242050
2 changed files with 28 additions and 3 deletions

View file

@ -56,3 +56,23 @@ func TimerStop(t *time.Timer) bool {
}
return true
}
// Run a blocking function with a timeout.
// Returns true if the function returns.
// Returns false if the timer fires.
// The blocked function remains blocked--the caller is responsible for somehow killing it.
func FuncTimeout(f func(), timeout time.Duration) bool {
success := make(chan struct{})
go func() {
defer close(success)
f()
}()
timer := time.NewTimer(timeout)
defer TimerStop(timer)
select {
case <-success:
return true
case <-timer.C:
return false
}
}