Skip to content

Commit

Permalink
feat(all): support iteratable tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
suguru03 committed Sep 22, 2018
1 parent a65887c commit 2cf7164
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { AigleProxy } = require('aigle-core');

const Aigle = require('./aigle');
const { INTERNAL, PENDING, promiseArrayEach, promiseSetEach } = require('./internal/util');
const { INTERNAL, PENDING, iteratorSymbol, promiseArrayEach, promiseSetEach } = require('./internal/util');
const { callResolve } = require('./props');

class All extends AigleProxy {
Expand All @@ -29,7 +29,7 @@ class All extends AigleProxy {
this._result = Array(size);
this._callResolve = callResolve;
promiseArrayEach(this);
} else if (array instanceof Set) {
} else if (array[iteratorSymbol]) {
const { size } = array;
this._rest = size;
this._coll = array;
Expand Down
6 changes: 6 additions & 0 deletions test/lib/test.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ parallel('all', () => {
return Aigle.all(tasks).then(res => assert.deepStrictEqual(res, [1, 2, 3]));
});

it('should work with iteratable tasks', () => {
const arr = [['task1', Aigle.delay(DELAY * 3, 1)], ['task2', Aigle.resolve(2)], ['task3', 3]];
const tasks = new Map(arr);
return Aigle.all(tasks).then(res => assert.deepStrictEqual(res, arr));
});

it('should catch an error', () => {
const order = [];
const delay = util.makeDelayTask(order);
Expand Down

0 comments on commit 2cf7164

Please sign in to comment.