15 lines
236 B
Go
15 lines
236 B
Go
|
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
|
||
|
}
|
||
|
|
||
|
}
|