dequeue(callback = (x, y) => y || x) { let limit = 1 return methods._getLatestAsync() .then(payload => { // if (!payload) { return callback(null, null) } if (!payload) { return callback(new QueueEmpty('Empty Queue'))} let {_id} = payload return Queue.removeAsync({_id}) .then(num => { if (num !== limit) { return methods.dequeue() // return Promise.reject(new Error('Race condition #fail! Try dequeue again. NOTE: Not production ready.')) } return callback(null, payload) }) }) .catch({message: /Race/}, err => { // if (/Race/.test(err.message)) return this.dequeue() // .catch(err => { // callback(err) // return Promise.reject(err) }) }
dequeue(callback = (x, y) => y || x) { let limit = 1 return methods._getLatestAsync() .then(payload => { // if (!payload) { return callback(null, null) } if (!payload) { return callback(new QueueEmpty('Empty Queue'))} let {_id} = payload return Queue.removeAsync({_id}) .then(num => { if (num !== limit) { return methods.dequeue() // return Promise.reject(new Error('Race condition #fail! Try dequeue again. NOTE: Not production ready.')) } return callback(null, payload) }) }) .catch({message: /Race/}, err => { // if (/Race/.test(err.message)) return this.dequeue() // .catch(err => { // callback(err) // return Promise.reject(err) }) }