mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 14:15:06 +03:00
fixes to linkInterface.handler()
This commit is contained in:
parent
def4fb3587
commit
2569242050
2 changed files with 28 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue