diff --git a/lib/race.js b/lib/race.js index 06a809d7..46dd6e9e 100644 --- a/lib/race.js +++ b/lib/race.js @@ -7,6 +7,9 @@ class Race extends Parallel { constructor(collection) { super(collection); this._result = undefined; + if (this._rest === 0) { + this._rest = -1; + } } _callResolve(value) { diff --git a/test/lib/test.race.js b/test/lib/test.race.js index 21922f78..3e377bd4 100644 --- a/test/lib/test.race.js +++ b/test/lib/test.race.js @@ -76,22 +76,49 @@ parallel('race', () => { }); }); - it('should return undefined if tasks is an empty array', () => { + it('should be pending if tasks is an empty array', () => { - return Aigle.race([]) - .then(res => assert.strictEqual(res, undefined)); + let called = false; + Aigle.race([]) + .then(() => called = true); + return Aigle.delay(DELAY) + .then(() => assert.strictEqual(called, false)); }); - it('should return undefined if tasks is an empty object', () => { + it('should be pending if tasks is an empty object', () => { - return Aigle.race({}) - .then(res => assert.strictEqual(res, undefined)); + let called = false; + Aigle.race({}) + .then(() => called = true); + return Aigle.delay(DELAY) + .then(() => assert.strictEqual(called, false)); }); it('should return undefined if tasks is empty', () => { - return Aigle.race() - .then(res => assert.strictEqual(res, undefined)); + let called = false; + Aigle.race() + .then(() => called = true); + return Aigle.delay(DELAY) + .then(() => assert.strictEqual(called, false)); + }); + + it('should return a resolved promise', () => { + return Aigle.race([ + Aigle.race(), + Aigle.resolve(1), + 2 + ]) + .then(res => assert.strictEqual(res, 1)); + }); + + it('should return a value', () => { + return Aigle.race([ + Aigle.race(), + 1, + Aigle.resolve(2) + ]) + .then(res => assert.strictEqual(res, 1)); }); });