Comparing version 1.17.1 to 1.18.0
{ | ||
"name": "fastq", | ||
"version": "1.17.1", | ||
"version": "1.18.0", | ||
"description": "Fast, in memory work queue", | ||
@@ -5,0 +5,0 @@ "main": "queue.js", |
24
queue.js
@@ -291,15 +291,15 @@ 'use strict' | ||
function drained () { | ||
if (queue.idle()) { | ||
return new Promise(function (resolve) { | ||
resolve() | ||
var p = new Promise(function (resolve) { | ||
process.nextTick(function () { | ||
if (queue.idle()) { | ||
resolve() | ||
} else { | ||
var previousDrain = queue.drain | ||
queue.drain = function () { | ||
if (typeof previousDrain === 'function') previousDrain() | ||
resolve() | ||
queue.drain = previousDrain | ||
} | ||
} | ||
}) | ||
} | ||
var previousDrain = queue.drain | ||
var p = new Promise(function (resolve) { | ||
queue.drain = function () { | ||
previousDrain() | ||
resolve() | ||
} | ||
}) | ||
@@ -306,0 +306,0 @@ |
@@ -249,1 +249,44 @@ 'use strict' | ||
}) | ||
test('drained should resolve after async tasks complete', async function (t) { | ||
const logs = [] | ||
async function processTask () { | ||
await new Promise(resolve => setTimeout(resolve, 0)) | ||
logs.push('processed') | ||
} | ||
const queue = buildQueue(processTask, 1) | ||
queue.drain = () => logs.push('called drain') | ||
queue.drained().then(() => logs.push('drained promise resolved')) | ||
await Promise.all([ | ||
queue.push(), | ||
queue.push(), | ||
queue.push() | ||
]) | ||
t.deepEqual(logs, [ | ||
'processed', | ||
'processed', | ||
'processed', | ||
'called drain', | ||
'drained promise resolved' | ||
], 'events happened in correct order') | ||
}) | ||
test('drained should handle undefined drain function', async function (t) { | ||
const queue = buildQueue(worker, 1) | ||
async function worker (arg) { | ||
await sleep(10) | ||
return arg | ||
} | ||
queue.drain = undefined | ||
queue.push(1) | ||
await queue.drained() | ||
t.pass('drained resolved successfully with undefined drain') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43454
15
1152