// Dequeue returns Enqueue()'d elements in FIFO order. If the
// queue is empty, Dequeue blocks until elements are available.
Dequeue returns Enqueue()'d elements in FIFO order. If the
queue is empty, Dequeue blocks until elements are available.
// Dequeue returns Enqueue () ' d elements in FIFO order . If the // queue is empty Dequeue blocks until elements are available .
func (q *Queue) Dequeue() (string, error) {
	resp, err := q.client.Get(q.ctx, q.keyPrefix, v3.WithFirstRev()...)
	if err != nil {
		return "", err
	}
	kv, err := claimFirstKey(q.client, resp.Kvs)
	if err != nil {
		return "", err
	} else if kv != nil {
		return string(kv.Value), nil
	} else if resp.More {
		return q.Dequeue()
	}
	ev, err := WaitPrefixEvents(
		q.client,
		q.keyPrefix,
		resp.Header.Revision,
		[]mvccpb.Event_EventType{mvccpb.PUT})
	if err != nil {
		return "", err
	}
	ok, err := deleteRevKey(q.client, string(ev.Kv.Key), ev.Kv.ModRevision)
	if err != nil {
		return "", err
	} else if !ok {
		return q.Dequeue()
	}
	return string(ev.Kv.Value), err
}
func ( q * Queue ) Dequeue ( ) ( string , error ) { resp , err := q . client . Get ( q . ctx , q . keyPrefix , v3 . WithFirstRev ( ) ... ) if err != nil { return " " , err } kv , err := claimFirstKey ( q . client , resp . Kvs ) if err != nil { return " " , err } else if kv != nil { return string ( kv . Value ) , nil } else if resp . More { return q . Dequeue ( ) } ev , err := WaitPrefixEvents ( q . client , q . keyPrefix , resp . Header . Revision , [ ] mvccpb . Event_EventType { mvccpb . PUT } ) if err != nil { return " " , err } ok , err := deleteRevKey ( q . client , string ( ev . Kv . Key ) , ev . Kv . ModRevision ) if err != nil { return " " , err } else if ! ok { return q . Dequeue ( ) } return string ( ev . Kv . Value ) , err }
Dequeue returns Enqueue()'d elements in FIFO order.
Dequeue returns Enqueue () ' d elements in FIFO order .
// TODO: fewer round trips by fetching more than one key // missed some items, retry to read in more // nothing yet; wait on elements