| // cancelChannel creates a channel usable by bqueue.Writer.Put and upcqueue.Get |
| // to cancel the calls if they have not completed by the provided deadline. |
| // A zero deadline (time.Time.IsZero) implies that no cancellation is desired. |
| func cancelChannel(deadline time.Time) chan struct{} { |
| sc := make(chan struct{}) |
| tc := time.After(deadline.Sub(time.Now())) |
| go func(dst chan struct{}, src <-chan time.Time) { |
| // timeoutError implements net.Error with Timeout returning true. |
| type timeoutError struct{} |
| func (t timeoutError) Error() string { return "deadline exceeded" } |
| func (t timeoutError) Timeout() bool { return true } |
| func (t timeoutError) Temporary() bool { return false } |