// OfferWithTime to enqueue key-value pair with time, timeout at `time`, if you
// would like to call Remove to delete the timeout object, `key` must be unique
// in this queue
OfferWithTime to enqueue key-value pair with time, timeout at `time`, if you
would like to call Remove to delete the timeout object, `key` must be unique
in this queue
// OfferWithTime to enqueue key - value pair with time timeout at ` time ` if you // would like to call Remove to delete the timeout object ` key ` must be unique // in this queue
func (q *TimeoutQueue) OfferWithTime(key, val interface{}, at time.Time) error {
	if atomic.LoadUint32(&q.running) == 0 {
		return ErrNotStarted
	}
	q.mu.Lock()
	defer q.mu.Unlock()
	select {
	case <-q.stop:
		return ErrStopped
	default:
		if _, ok := q.blackList[key]; ok {
			return ErrKeyNotAllowed
		}
	}
	expireAt := at.UTC().UnixNano()
	q.data = append(q.data, &TimeoutData{Key: key, Data: val, expireAt: expireAt})
	q.index[key] = len(q.data) - 1
	if len(q.data) == 1 || q.nextSort > expireAt {
		q.nextSort = expireAt
		select {
		case <-q.stop:
			return ErrStopped
		case q.resetCh <- expireAt - time.Now().UTC().UnixNano():
		}
	}
	return nil
}
func ( q * TimeoutQueue ) OfferWithTime ( key , val interface { } , at time . Time ) error { if atomic . LoadUint32 ( & q . running ) == 0 { return ErrNotStarted } q . mu . Lock ( ) defer q . mu . Unlock ( ) select { case <- q . stop : return ErrStopped default : if _ , ok := q . blackList [ key ] ; ok { return ErrKeyNotAllowed } } expireAt := at . UTC ( ) . UnixNano ( ) q . data = append ( q . data , & TimeoutData { Key : key , Data : val , expireAt : expireAt } ) q . index [ key ] = len ( q . data ) - 1 if len ( q . data ) == 1 || q . nextSort > expireAt { q . nextSort = expireAt select { case <- q . stop : return ErrStopped case q . resetCh <- expireAt - time . Now ( ) . UTC ( ) . UnixNano ( ) : } } return nil }
OfferWithTime to enqueue key-value pair with time, timeout at `time`, if you
would like to call Remove to delete the timeout object, `key` must be unique
in this queue
OfferWithTime to enqueue key - value pair with time timeout at ` time ` if you would like to call Remove to delete the timeout object ` key ` must be unique in this queue
// the added item is the only one in the queue or // the next sort will be after this expiration