Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-promise-series

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-promise-series - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

.npmignore

54

index.js
"use strict";
module.exports = function(Promise)
{
Promise.series = function(promises) {
var promises = promises.slice();
var results = [];
var first = true;
module.exports = function(Promise) {
Promise.series = function (promises, concurrent) {
var results = null;
promises = promises.slice();
concurrent = concurrent || 1;
return new Promise(function(resolve, reject) {
function next(result)
{
if (!first) {
results.push(result);
return new Promise(function (resolve, reject) {
function next(result) {
console.log('next', promises.length, (new Date()).getTime());
var concurrentPromises = [];
var promise;
if (!results) {
results = [];
} else {
results = results.concat(result);
}
else {
first = false;
}
if (promises.length) {
var promise = promises.shift();
while (concurrentPromises.length < concurrent && promises.length) {
var promise = promises.shift();
if (!promise || typeof promise.then !== 'function') {
promise = Promise.resolve();
if (typeof promise === 'function') {
promise = promise();
}
if (!promise || typeof promise.then !== 'function') {
promise = Promise.resolve();
}
concurrentPromises.push(promise);
}
promise
.then(next)
.catch(reject);
}
else {
Promise.all(concurrentPromises)
.then(next)
.catch(reject);
} else {
resolve(results);

@@ -38,3 +46,3 @@ }

});
}
};
};
{
"name": "es6-promise-series",
"version": "0.0.2",
"version": "0.1.0",
"description": "Execute promises in series",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node node_modules/.bin/mocha index.test.js"
},

@@ -23,3 +23,7 @@ "repository": {

},
"homepage": "https://github.com/der-On/es6-promise-series"
"homepage": "https://github.com/der-On/es6-promise-series",
"devDependencies": {
"expect.js": "^0.3.1",
"mocha": "^2.3.4"
}
}

@@ -0,1 +1,3 @@

[![Build Status](https://travis-ci.org/der-On/es6-promise-series.svg)](https://travis-ci.org/der-On/es6-promise-series)
# ES6 Promise.series

@@ -6,6 +8,12 @@

```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([
aPromise,
anotherPromise
])
], 4)
.then(function (results) {

@@ -12,0 +20,0 @@ ...

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc