Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-handlers

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-handlers

Function factories for performing synchronous operations after asynchronous operations

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by54.55%
Maintainers
1
Weekly downloads
 
Created
Source

Asynchronous handlers

Function factories for performing synchronous operations after asynchronous operations.

f1 = function (callback) {
  asyncOperation(function(err, result) {
    if (err) {
      callback(err);
    } else {
      callback(null, syncOperation(result);
    }
  }
}

// is equivalent to

var asyncHandlers = require('async-handlers')

f1 = function (callback) {
  handler = asyncHandlers.transform(syncOperation, callback);
  asyncOperation(handler);
}

Methods

constant(value, callback)

Returns a function with the signature (err). When called with an error, passes it to the callback. Otherwise executes callback with (null, value).

exitOnError

Returns a function with the signature (err). When called with an error, prints the error in red to stderr and exits with status 1. Otherwise does nothing.

extract(key, callback)

Returns a function with the signature (err, result). When called with an error, passes it to the callback. Otherwise executes callback with (null, result[key]).

prependToError(prefix, callback)

Returns a function with the signature (err, args...). When error is a string, prepends prefix to it if and passes it to the callback. When error is an object with a message property, prepends prefix to its message and passes it to the callback. Otherwise passes all arguments to the callback.

Note: the prefix will only be prepended if not already present.

transform(fn, callback)

Returns a function with the signature (err, result). When called with an error, passes it to the callback. Otherwise executes callback with (null, fn(result)).

FAQs

Package last updated on 28 Jul 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc