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

async-or

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

async-or

Run tasks in paralelle, and take the result from either the first (by list-order) task that succeeds, or, if none succeed, the last tasks error.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

async-or

Run tasks in parallel, and take the result from either the first (by list-order) task that succeeds, or, if none succeed, the last tasks error.

Usage

pass an array of tasks that take a callback as their first parameter, and a callback:


function works1(done){
    setTimeout(function(){
        done(null, 1);
    }, 100);
}

function works2(done){
    setTimeout(function(){
        done(null, 2);
    }, 200);
}

asyncOr([works1, works2], function(error, result){
    error; // -> null
    result; // -> 1
});

Tasks are run in parallel, and the first task in the task list that succeeds will resolve the callback.

eg:

given tasks: [a, b, c]

  • if a succeeds, it will resolve the callback.

  • if a fails, and b succeeds, b will resolve the callback.

  • if a, b, and c fail, the callback will be resolved with c's error.

  • The chronological order in which tasks complete has no impact on which task will resolve the callback. *

See the tests for a more in-depth explaination of cases.

FAQs

Package last updated on 22 Jun 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

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