es6-promise-series
Advanced tools
Comparing version 0.1.1 to 0.2.0
24
index.js
"use strict"; | ||
module.exports = function(Promise) { | ||
Promise.series = function (promises, concurrent) { | ||
function promiseSupported(Promise){ | ||
return typeof Promise !== "undefined" && Promise.toString().indexOf("[native code]") !== -1; | ||
} | ||
module.exports = function(_Promise) { | ||
if (!promiseSupported(Promise)){ | ||
throw new Error("Promise not supported"); | ||
} | ||
if (_Promise && typeof _Promise.all === "function" && typeof _Promise.race === "function"){ | ||
return arguments[0].series = series; | ||
} else { | ||
return series.apply(this, arguments); | ||
} | ||
}; | ||
function series (promises, concurrent) { | ||
var results = null; | ||
@@ -45,3 +62,2 @@ promises = promises.slice(); | ||
}); | ||
}; | ||
}; | ||
} |
{ | ||
"name": "es6-promise-series", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Execute promises in series", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node node_modules/.bin/mocha index.test.js" | ||
"test": "_mocha *.test.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -7,2 +7,4 @@ [![Build Status](https://travis-ci.org/der-On/es6-promise-series.svg)](https://travis-ci.org/der-On/es6-promise-series) | ||
Usage | ||
```javascript | ||
@@ -15,2 +17,22 @@ /** | ||
*/ | ||
import series from 'series' | ||
series([ | ||
aPromise, | ||
anotherPromise | ||
], 4) | ||
.then(function (results) { | ||
... | ||
}); | ||
``` | ||
Old usage | ||
```javascript | ||
/** | ||
* Runs promises in series | ||
* @param {Array} list of promises or functions returning promises | ||
* @param {Number} (optional) number of concurrent promises, of omitted no concurrency will happen | ||
* @return {Promise} | ||
*/ | ||
Promise.series([ | ||
@@ -24,1 +46,2 @@ aPromise, | ||
``` | ||
6481
7
185
45