func()

in persistence/queue.go [67:98]


func (vq *valueQueue) Dequeue(obj interface{}) error {
	var queue []json.RawMessage
	// Grab the value's associated persistence lock
	vq.value.mutex().Lock()
	defer vq.value.mutex().Unlock()
	// First, load the existing queue
	if err := vq.value.load(&queue); err != nil {
		return err
	}
	// If the queue exists but is somehow empty, we return ErrNotFound
	if len(queue) == 0 {
		return ErrNotFound
	}
	// If the caller passed a non-nil obj, store the value currently at the front of the queue.
	if obj != nil {
		if err := json.Unmarshal(queue[0], obj); err != nil {
			return err
		}
	}
	// Remove the front. If the new queue still has entries, store it. Else, remove the backing value.
	newq := queue[1:]
	if len(newq) > 0 {
		if err := vq.value.store(queue[1:]); err != nil {
			return err
		}
	} else {
		if err := vq.value.remove(); err != nil {
			return err
		}
	}
	return nil
}