예제 #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
}
예제 #2
0
파일: task.go 프로젝트: zwczou/goserver
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
}
예제 #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
}