async peek(n = 1, options = null) { const queues = await this.getQueuesFunc(); const qServices = shuffle(this._getQServices(queues)); const perQ = qServices.length > 1 ? Math.floor(n / qServices.length) : qServices.length; // First, iterate evenly and randomly on status queues const partial = await this._peek(qServices, perQ, options); if (partial.done) { return partial.result; } let messagesLeftToPeek = n - partial.result.length; // In case queues are uneven, iterate again. This time, request for all n messages and trim return await this._peek(partial.result.nonEmptyQs, messagesLeftToPeek, options); }
async pop(n = 1, options = null) { const queues = await this.getQueuesFunc(); const qServices = shuffle(this._getQServices(queues)); const perQ = qServices.length > 1 ? Math.floor(n / qServices.length) : qServices.length; // First, iterate evenly and randomly on status queues const partial = await this._pop(qServices, perQ, options); if (partial.done) { return partial.result; } let messagesLeftToPop = n - partial.result.length; // In case queues are uneven, iterate again. This time, request for all n messages and trim const final = await this._pop(partial.result.nonEmptyQs, messagesLeftToPop, options); return partial.result.concat(final.result); }