Socket
Book a DemoInstallSign in
Socket

finally-aggregator

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

finally-aggregator

A simple utility for aggregating cleanup functions for async programming problems.

Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
7
250%
Maintainers
1
Weekly downloads
 
Created
Source

Finally Aggregator

A simple utility for aggregating cleanup functions for async programming problems.

var FinallyAggregator = require('finally-aggregator');
var cleaner = new FinallyAggregator();

Example problem and solution

inParallel(
  [
    createTmpFile,
    performActionThatErrors
  ],
  function (err) {
    // how do I tell createTempFile to cleanup!?
  }
);
function createTmpFile(cleaner, next) {
  /// ...
  cleaner.add(cleanupTmpFile);
  next();
}
inParallel(
  [
    createTmpFile.bind(null, cleaner),
    performActionThatErrors.bind(null, cleaner)
  ],
  function (err) {
    if (err) cleaner.finish();
  }
);

What it does

  • The FinallyAggregator will queue up functions by using .add(fn).
  • Once .finish() is called all queued functions will execute.
  • If .add(fn) is called after .finish() it will execute immediately.

This lets us queue up cleanup if we have not reached a point where cleanup is desired, or perform cleanup if we have passed the point where cleanup is called for.

FAQs

Package last updated on 25 Jun 2015

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