mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
4a0a15586b
Fix all the linter problems for the `v0.16.0-beta.rc3`.
19 lines
378 B
Go
19 lines
378 B
Go
package lnutils
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// RecvOrTimeout attempts to recv over chan c, returning the value. If the
|
|
// timeout passes before the recv succeeds, an error is returned.
|
|
func RecvOrTimeout[T any](c <-chan T, timeout time.Duration) (*T, error) {
|
|
select {
|
|
case m := <-c:
|
|
return &m, nil
|
|
|
|
case <-time.After(timeout):
|
|
return nil, fmt.Errorf("timeout hit")
|
|
}
|
|
}
|