Socket
Book a DemoInstallSign in
Socket

promise-sequential

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-sequential

Simple like Promise.all(), but sequentially!

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

promise-sequential

Simple like Promise.all(), but sequentially!

NPM version

Npm Downloads

Installation

npm install --save promise-sequential

Usage

const sequential = require('promise-sequential');

const items = [
  () => new Promise( ... )
  () => new Promise( ... )
  () => new Promise( ... )
];

sequential(items)
.then(res => {
  // ...
})
.catch(err => {
  // ...
})

There is only one difference between Promise.all usage and promise-sequential usage: promise-sequential receive an Array of functions that each returns a promise.

Each function brings three params:

NameDescription
previousResponseThe response of previous iteration
responsesAll responses received at the time
countThe current count.

More complex usage


const sequential = require('promise-sequential');
const array = [1,2,3,4,5];

sequential(array.map((item) => {
  return function(previousResponse, responses, count) {

    return new Promise(resolve => {
      setTimeout(() => {
        resolve(item)
      }, 1000)
    })

  }
}))
.then(res => {
  // ...
})
.catch(err => {
  // ...
})

Keywords

promise

FAQs

Package last updated on 20 Sep 2016

Did you know?

Socket

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