
ChannelReceivesSomething (formerly WaitForChannel) originally was located in the helpers package. This move was done to remove a cyclic dependency with the nomand package.
15 lines
399 B
Go
15 lines
399 B
Go
package tests
|
|
|
|
import "time"
|
|
|
|
// ChannelReceivesSomething waits timeout seconds for something to be received from channel ch.
|
|
// If something is received, it returns true. If the timeout expires without receiving anything, it return false.
|
|
func ChannelReceivesSomething(ch chan bool, timeout time.Duration) bool {
|
|
select {
|
|
case <-ch:
|
|
return true
|
|
case <-time.After(timeout):
|
|
return false
|
|
}
|
|
}
|