New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@aymkdn/promisechain

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aymkdn/promisechain

Permits to sequentially execute Promise requests one by one

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

PromiseChain

Promise.all will execute all requets at the same time, but it often happens the case where you want to execute requests one by one, until all requests have been executed.

It's what PromiseChain is doing; executing sequentially the requests upon full resolution.

Installation

npm install @aymkdn/promisechain

Usage

const PromiseChain = require("@aymkdn/promisechain");
let arr = ["one", "two", "three"];

// Example with `Promise.all`
Promise.all(arr.map((item,i) => {
  console.log(item);
  return new Promise(prom_res => {
    setTimeout(() => {
      console.log(item+" completed.");
      prom_res(item);
    }, 1000*i)
  })
}))

/*
The result for Promise.all:
one
two
three
one completed.
two completed.
three completed.
*/

// Same example with `PromiseChain`
PromiseChain(arr, (item,i) => {
  console.log(item);
  return new Promise(prom_res => {
    setTimeout(() => {
      console.log(item+" completed.");
      prom_res(item);
    }, 1000*i)
  })
})

/*
The result for PromiseChain:
one
one completed.
two
two completed.
three
three completed.
*/

Keywords

promise

FAQs

Package last updated on 19 Aug 2019

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