websvc: add test; imp names, docs

This commit is contained in:
Ainar Garipov
2022-09-02 18:52:22 +03:00
parent 8a65848da4
commit abcbdbed29
11 changed files with 218 additions and 57 deletions

View 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
}
}