This commit is contained in:
2022-11-30 23:34:16 +01:00
parent 496c4e4f59
commit bdf5b53c20
3 changed files with 210 additions and 4 deletions

14
syncext/channel.go Normal file
View 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
}
}