synchronous-promise
Advanced tools
Comparing version
@@ -140,4 +140,5 @@ 'use strict'; | ||
allData = [], | ||
numResolved = 0, | ||
doResolve = function () { | ||
if (allData.length === args.length) { | ||
if (numResolved === args.length) { | ||
resolve(allData); | ||
@@ -154,5 +155,6 @@ } | ||
}; | ||
args.forEach(function (arg) { | ||
args.forEach(function (arg, idx) { | ||
arg.then(function (thisResult) { | ||
allData.push(thisResult); | ||
allData[idx] = thisResult; | ||
numResolved += 1; | ||
doResolve(); | ||
@@ -159,0 +161,0 @@ }).catch(function (err) { |
@@ -429,2 +429,25 @@ /* | ||
}); | ||
it('should resolve with values in the correct order', function() { | ||
var | ||
resolve1, | ||
resolve2, | ||
captured; | ||
var p1 = create(function(resolve) { | ||
resolve1 = resolve; | ||
}); | ||
var p2 = create(function(resolve) { | ||
resolve2 = resolve; | ||
}); | ||
SynchronousPromise.all([p1, p2]).then(function(data) { | ||
captured = data; | ||
}); | ||
resolve2('a'); | ||
resolve1('b'); | ||
expect(captured).to.deep.equal(['b', 'a']); | ||
}); | ||
it('should reject if any promise rejects', function () { | ||
@@ -431,0 +454,0 @@ var |
{ | ||
"name": "synchronous-promise", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Synchronous Promise-like prototype to use in testing where you would have used an ES6 Promise", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -59,3 +59,3 @@ # synchronous-promise | ||
``` | ||
***And there's nothing with this strategy.*** | ||
***And there's nothing wrong with this strategy.*** | ||
@@ -202,2 +202,2 @@ I need to put that out there before anyone takes offense or thinks that I'm suggesting | ||
I've tried to implement every behaviour I'd expect from a promise -- but I'm | ||
pretty sure that a native `Promise` will be better for production code any day. | ||
pretty sure that a native `Promise` will be better for production code any day. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
671
3.07%202
0.5%30052
-1.15%