websvc: add test; imp names, docs
This commit is contained in:
19
internal/aghchan/aghchan.go
Normal file
19
internal/aghchan/aghchan.go
Normal file
@@ -0,0 +1,19 @@
|
||||
// Package aghchan contains channel utilities.
|
||||
package aghchan
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// MustReceive panics if it cannot receive a value form c before timeout runs
|
||||
// out.
|
||||
func MustReceive[T any](c <-chan T, timeout time.Duration) (v T, ok bool) {
|
||||
timeoutCh := time.After(timeout)
|
||||
select {
|
||||
case <-timeoutCh:
|
||||
panic(fmt.Errorf("did not receive after %s", timeout))
|
||||
case v, ok = <-c:
|
||||
return v, ok
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user