summaryrefslogtreecommitdiff
path: root/test/es2017
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2019-05-19 18:30:18 -0700
committerGitHub <noreply@github.com>2019-05-19 18:30:18 -0700
commite0446642d70817f4353b4ed12a3c86e5d769cf01 (patch)
treea6a492683ec0550b9dd55edd0ac29e039885b37e /test/es2017
parent1d458d980a8bfee8c941061dca364a33cf15fac0 (diff)
downloadasync-e0446642d70817f4353b4ed12a3c86e5d769cf01.tar.gz
BREAKING CHANGE: awaitable queues (#1641)
* BREAKING CHANGE: awaitable queues * fix priorityQueue tests * fix tests in firefox * make the upgrade a bit more user-friendly * clarify docs
Diffstat (limited to 'test/es2017')
-rw-r--r--test/es2017/asyncFunctions.js12
-rw-r--r--test/es2017/awaitableFunctions.js45
2 files changed, 51 insertions, 6 deletions
diff --git a/test/es2017/asyncFunctions.js b/test/es2017/asyncFunctions.js
index 553b7f4..bf0d708 100644
--- a/test/es2017/asyncFunctions.js
+++ b/test/es2017/asyncFunctions.js
@@ -350,10 +350,10 @@ module.exports = function () {
result.push(await Promise.resolve(val));
}, 2)
- q.drain = () => {
+ q.drain(() => {
expect(result).to.eql([[1, 2], [3]]);
done();
- };
+ });
q.push(1);
q.push(2);
@@ -366,10 +366,10 @@ module.exports = function () {
result.push(await Promise.resolve(val));
}, 2)
- q.drain = () => {
+ q.drain(() => {
expect(result).to.eql([1, 2, 3]);
done();
- };
+ });
q.push(1);
q.push(2);
@@ -382,10 +382,10 @@ module.exports = function () {
result.push(await Promise.resolve(val));
}, 2)
- q.drain = () => {
+ q.drain(() => {
expect(result).to.eql([1, 2, 3]);
done();
- };
+ });
q.push(1);
q.push(2);
diff --git a/test/es2017/awaitableFunctions.js b/test/es2017/awaitableFunctions.js
index 55bcc9e..e8adf7b 100644
--- a/test/es2017/awaitableFunctions.js
+++ b/test/es2017/awaitableFunctions.js
@@ -586,6 +586,51 @@ module.exports = function () {
expect(calls).to.eql([1, 2, 3, 4])
});
+ it('should work with queues', async () => {
+ const q = async.queue(async (data) => {
+ if (data === 6) throw new Error('oh noes')
+ await new Promise(resolve => setTimeout(resolve, 10))
+ return data
+ }, 5)
+
+ const calls = []
+ const errorCalls = []
+ const emptyCalls = []
+ q.error().catch(d => errorCalls.push('error ' + d))
+ q.saturated().then(() => calls.push('saturated'))
+ q.unsaturated().then(() => calls.push('unsaturated'))
+ q.empty().then(() => emptyCalls.push('empty'))
+
+ q.push(1).then(d => calls.push('push cb ' + d))
+ q.push(2).then(d => calls.push('push cb ' + d))
+ q.push([3, 4, 5, 6]).map(p => p.then(d => calls.push('push cb ' + d)))
+ q.push(7).then(d => calls.push('push cb ' + d))
+ q.push(8).then(d => calls.push('push cb ' + d))
+
+ const multiP = Promise.all(q.push([9, 10]))
+
+ await q.drain()
+ await multiP
+ expect(calls).to.eql([
+ 'saturated',
+ 'push cb 1',
+ 'push cb 2',
+ 'push cb 3',
+ 'push cb 4',
+ 'push cb 5',
+ 'push cb 7',
+ 'unsaturated',
+ 'push cb 8'
+ ])
+
+ expect(errorCalls).to.eql([
+ 'error Error: oh noes',
+ ])
+ expect(emptyCalls).to.eql([
+ 'empty',
+ ])
+ })
+
/*
* Util
*/