v0.0.24
This commit is contained in:
14
syncext/channel.go
Normal file
14
syncext/channel.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package dataext
|
||||
|
||||
import "time"
|
||||
|
||||
func ReadChannelWithTimeout[T any](c chan T, timeout time.Duration) (T, bool) {
|
||||
afterCh := time.After(timeout)
|
||||
select {
|
||||
case rv := <-c:
|
||||
return rv, true
|
||||
case <-afterCh:
|
||||
return *new(T), false
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user