Skip to content

Commit

Permalink
Merge c7e5a67 into e64e333
Browse files Browse the repository at this point in the history
  • Loading branch information
JefStat committed Jan 24, 2020
2 parents e64e333 + c7e5a67 commit 1594866
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ export default function queue(worker, concurrency, payload) {

const eventMethod = (name) => (handler) => {
if (!handler) {
return new Promise((resolve, reject) => {
const p = new Promise((resolve, reject) => {
once(name, (err, data) => {
if (err) return reject(err)
resolve(data)
})
})
_maybeDrain([]);
return p;
}
off(name)
on(name, handler)

}

var isProcessing = false;
Expand Down
20 changes: 20 additions & 0 deletions test/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ describe('queue', function(){
done();
});

it('correctly awaitable', async () => {
var q = async.queue((t, cb) => cb(null, t));
q.push(1, () => {});
// double await
const p = await q.drain();
await p;

// await on empty queue
const p2 = q.drain();
await p2;

// await on queue refilled
q.push(1, () => {});
const p3 = q.drain();
await p3;
expect(p).to.not.eql(p2);
expect(p).to.not.eql(p3);
expect(p2).to.not.eql(p3);
});

it('error propagation', (done) => {
var results = [];

Expand Down

0 comments on commit 1594866

Please sign in to comment.