Socket
Socket
Sign inDemoInstall

promise-serial

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    promise-serial

Run promises in series


Version published
Weekly downloads
95
decreased by-11.21%
Maintainers
1
Install size
638 kB
Created
Weekly downloads
 

Readme

Source
Usage
// example.js
const Promise_serial = require('promise-serial');


const promises =
    Array(15).fill()
    .map((_, i) =>
        () => new Promise(resolve => {
            console.log('promise '+i+' start');
            setTimeout(
                () => {
                    console.log('promise '+i+' end');
                    resolve('output-'+i);
                },
                500
            );
        })
    );


console.log('### Run promises in sequence')
Promise_serial(promises)
.then(() => {
    console.log('### Run promises in series of 5')
    return Promise_serial(promises, {parallelize: 5});
})
.then(output => {
    console.log('### Run promises in series of 10')
    return (
        Promise_serial(promises, {parallelize: 10})
        .then(output => {console.log('Resolved values: '+JSON.stringify(output))})
    );
});

node example.js prints:

### Run all promises in sequence
promise 0 start
promise 0 end
promise 1 start
promise 1 end
promise 2 start
promise 2 end
promise 3 start
promise 3 end
promise 4 start
promise 4 end
promise 5 start
promise 5 end
promise 6 start
promise 6 end
promise 7 start
promise 7 end
promise 8 start
promise 8 end
promise 9 start
promise 9 end
promise 10 start
promise 10 end
promise 11 start
promise 11 end
promise 12 start
promise 12 end
promise 13 start
promise 13 end
promise 14 start
promise 14 end
### Run all promises in series of 5
promise 0 start
promise 1 start
promise 2 start
promise 3 start
promise 4 start
promise 0 end
promise 1 end
promise 2 end
promise 3 end
promise 4 end
promise 5 start
promise 6 start
promise 7 start
promise 8 start
promise 9 start
promise 5 end
promise 6 end
promise 7 end
promise 8 end
promise 9 end
promise 10 start
promise 11 start
promise 12 start
promise 13 start
promise 14 start
promise 10 end
promise 11 end
promise 12 end
promise 13 end
promise 14 end
### Run all promises in series of 10
promise 0 start
promise 1 start
promise 2 start
promise 3 start
promise 4 start
promise 5 start
promise 6 start
promise 7 start
promise 8 start
promise 9 start
promise 0 end
promise 1 end
promise 2 end
promise 3 end
promise 4 end
promise 5 end
promise 6 end
promise 7 end
promise 8 end
promise 9 end
promise 10 start
promise 11 start
promise 12 start
promise 13 start
promise 14 start
promise 10 end
promise 11 end
promise 12 end
promise 13 end
promise 14 end
Resolved values: ["output-0","output-1","output-2","output-3","output-4","output-5","output-6","output-7","output-8","output-9","output-10","output-11","output-12","output-13","output-14"]

FAQs

Last updated on 08 Aug 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc