// Run this function as a goroutine
Run this function as a goroutine
// Run this function as a goroutine
func (q *Queue) Run() error {
	q.Cancel()
	if q.delay < 1 {
		return errInvalidDelayProvided
	}
	currDelay := int64(-1)
	currNow := time.Now().UnixNano()
	prevNow := currNow
	context, cancel := context.WithCancel(context.Background())
	q.cancelCallback = &cancel
	for {
		select {
		case <-context.Done():
			return context.Err()
		default:
			if currDelay > 0 {
				prevNow = currNow
				currNow = time.Now().UnixNano()
				currDelay -= currNow - prevNow
				continue
			}
			queuePayload, errQueuePayload := updateQueueRequests(
				q.cacheAddress,
				q.identifier,
				nil,
			)
			if queuePayload == nil || errQueuePayload != nil {
				currDelay = q.delay
				continue
			}
			errCallback := (*q.callback)(
				queuePayload,
				&cancel,
				errQueuePayload,
			)
			if errCallback != nil {
				return errCallback
			}
		}
	}
	return nil
}
func ( q * Queue ) Run ( ) error { q . Cancel ( ) if q . delay < 1 { return errInvalidDelayProvided } currDelay := int64 ( - 1 ) currNow := time . Now ( ) . UnixNano ( ) prevNow := currNow context , cancel := context . WithCancel ( context . Background ( ) ) q . cancelCallback = & cancel for { select { case <- context . Done ( ) : return context . Err ( ) default : if currDelay > 0 { prevNow = currNow currNow = time . Now ( ) . UnixNano ( ) currDelay -= currNow - prevNow continue } queuePayload , errQueuePayload := updateQueueRequests ( q . cacheAddress , q . identifier , nil , ) if queuePayload == nil || errQueuePayload != nil { currDelay = q . delay continue } errCallback := ( * q . callback ) ( queuePayload , & cancel , errQueuePayload , ) if errCallback != nil { return errCallback } } } return nil }
Run this function as a goroutine
Run this function as a goroutine