Beispiel #1
0
func (q *queueC) Enqueue(i interface{}, timeout time.Duration) bool {
	if timeout > 0 {
		timer := recycler.GetTimer(timeout)
		defer recycler.GiveTimer(timer)

		select {
		case q.c <- i:
		case <-timer.C:
			return false
		}
	} else {
		q.c <- i
	}

	return true
}
Beispiel #2
0
func (t *Task) GetWithTimeout(timeout time.Duration) interface{} {
	if timeout == 0 {
		return t.Get()
	} else {
		timer := recycler.GetTimer(timeout)
		defer recycler.GiveTimer(timer)
		select {
		case r, ok := <-t.r:
			if ok {
				return r
			} else {
				return nil
			}
		case <-timer.C:
			return nil
		}
	}
	return nil
}
Beispiel #3
0
func (q *queueC) Dequeue(timeout time.Duration) (i interface{}, ok bool) {
	if timeout > 0 {
		timer := recycler.GetTimer(timeout)
		defer recycler.GiveTimer(timer)

		select {
		case i, ok = <-q.c:
			return i, ok
		case <-timer.C:
			return nil, false
		}
	} else {
		select {
		case i, ok = <-q.c:
			return i, ok
		}
	}
	return nil, false
}