@@ -39,20 +39,17 @@ const (
3939// WithTimeout wraps a generic channel and provides a timed receive operation.
4040type WithTimeout struct {
4141 ch chan interface {}
42- // RecvTimeout is the timeout duration for receive operations on the
43- // underlying channel.
44- RecvTimeout time.Duration
4542}
4643
4744// Send sends value on the underlying channel.
4845func (cwt * WithTimeout ) Send (value interface {}) {
4946 cwt .ch <- value
5047}
5148
52- // Receive returns the value received on the underlying channel, or
53- // ErrRecvTimeout if the operation times out .
54- func (cwt * WithTimeout ) Receive ( ) (interface {}, error ) {
55- timer := time .NewTimer (cwt . RecvTimeout )
49+ // TimedReceive returns the value received on the underlying channel, or
50+ // ErrRecvTimeout if timeout amount of time elapsed .
51+ func (cwt * WithTimeout ) TimedReceive ( timeout time. Duration ) (interface {}, error ) {
52+ timer := time .NewTimer (timeout )
5653 select {
5754 case <- timer .C :
5855 return nil , ErrRecvTimeout
@@ -62,15 +59,13 @@ func (cwt *WithTimeout) Receive() (interface{}, error) {
6259 }
6360}
6461
65- // NewChanWithTimeout makes a WithTimeout channel using the defaults.
66- func NewChanWithTimeout () * WithTimeout {
67- return NewChan (DefaultRecvTimeout , DefaultBufferSize )
62+ // Receive returns the value received on the underlying channel, or
63+ // ErrRecvTimeout if DefaultRecvTimeout amount of time elapses.
64+ func (cwt * WithTimeout ) Receive () (interface {}, error ) {
65+ return cwt .TimedReceive (DefaultRecvTimeout )
6866}
6967
70- // NewChan makes a WithTimeout channel using the provided timeout and bufSize.
71- func NewChan (timeout time.Duration , bufSize int ) * WithTimeout {
72- return & WithTimeout {
73- ch : make (chan interface {}, bufSize ),
74- RecvTimeout : timeout ,
75- }
68+ // NewChan returns a new WithTimeout channel.
69+ func NewChan () * WithTimeout {
70+ return & WithTimeout {ch : make (chan interface {}, DefaultBufferSize )}
7671}
0 commit comments