Comparing version 0.0.7 to 0.0.8
@@ -227,13 +227,18 @@ 'use strict'; | ||
// any - the first to resolve, wins - else reject with all of the errors | ||
Promish.any = Promise.any || function(promises) { | ||
// some - the first n to resolve, win - else reject with all of the errors | ||
Promish.some = Promise.some || function(promises, n) { | ||
return new Promish(function(resolve, reject) { | ||
var values = []; | ||
var rejects = []; | ||
var countDown = promises.length; | ||
promises.forEach(function(promise, index) { | ||
promises.forEach(function(promise) { | ||
promise | ||
.then(resolve) | ||
.then(function(value) { | ||
values.push(value); | ||
if (values.length >= n) { | ||
resolve(values); | ||
} | ||
}) | ||
.catch(function(error) { | ||
rejects[index] = error; | ||
if (--countDown === 0){ | ||
rejects.push(error); | ||
if (rejects.length > promises.length - n){ | ||
reject(rejects); | ||
@@ -246,2 +251,10 @@ } | ||
// any - the first to resolve, wins - else reject with all of the errors | ||
Promish.any = Promise.any || function(promises) { | ||
return Promish.some(promises, 1) | ||
.then(function(values) { | ||
return values[0]; | ||
}); | ||
}; | ||
// old-style for ease of adoption | ||
@@ -248,0 +261,0 @@ Promish.defer = function() { |
{ | ||
"name": "promish", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "ES6 Promise Shim", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -23,3 +23,3 @@ # Promish | ||
<ul> | ||
<li>Bugfixes and Documentation</li> | ||
<li><a href="some">Some</a></li> | ||
</ul> | ||
@@ -381,2 +381,17 @@ | ||
## Some | ||
Resolve on first N successful promises or reject with array of errors. | ||
```javascript | ||
Promish.some([promise1, promise2, promise3], 2) | ||
.then(function(values) { | ||
// first 2 successful promises... | ||
}) | ||
.catch(function(errors) { | ||
// at least 2 promises failed | ||
}); | ||
``` | ||
## Any | ||
@@ -383,0 +398,0 @@ |
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
20013
243
440