Socket
Book a DemoInstallSign in
Socket

all-finished

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

all-finished

Synchronise JavaScript processes

3.1.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

all-finished

Execute a function when pre-conditions have been satisfied (probably asynchronously).

Build Status Coverage Status Dependencies npm version Greenkeeper badge

Whilst JavaScript is single-threaded, it's async nature means that there can be multiple logical processes. all-finished is a tiny utility to assist with synchronising asynchronous calls. This is conceptually similar to Promise.all from the JavaScript promise api, or Thread.join in Java or C#.

Getting started

Install via NPM

npm i all-finished --save

Example usage

const AllFinished = require('all-finished');

const all = AllFinished();
const firstThingDone = all.track();
const secondThingDone = all.track();

all.finished((allArgs) => {
  // Do something now that firstThingDone and secondThingDone have both been executed
  console.log(allArgs[0]); // => ['first optional param']
});

setTimeout(() => {
  firstThingDone('first optional param');
}, 100);

setTimeout(() => {
  secondThingDone('second optional param');
}, 200);

API

All()

Creates a new all tracking object.

all.track()

Returns a tracking function, when all tracking functions have been executed, the finished handler is executed. Any parameters passed to the tracking function are also passed to the finished handler.

all.finished(handler)

Takes a handling function as a parameter which is executed when all created tracking functions have been executed. The handler receives the parameters passed to the tracking functions, in the order that the tracking functions were created with all.track().

License

MIT

Keywords

async

FAQs

Package last updated on 27 Oct 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.