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

async-any

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

async-any

Manage various forms of asynchronous completion in a uniform way

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

async-any

Build Status NPM Version

NAME

async-any - manage various forms of asynchronous completion in a uniform way

INSTALLATION

$ npm install async-any

SYNOPSIS

import asyncAny from 'async-any'

// async task taking a `done` callback
asyncAny(done => fs.stat(path, done), (error, result) => { ... })

// async task returning a promise or observable
asyncAny(() => fetch(url), (error, result) => { ... })

// returns a promise if the callback is omitted
let result = await asyncAny(task)

DESCRIPTION

This module exports a function which provides a uniform way to handle tasks which signal completion asynchronously — either by calling a callback, returning a promise, or returning an observable.

Why?

I wanted a lightweight version of async-done without the bugs, with stricter detection of promises and observables, with an optional promise API, and with browser support.

Why Not?

async-any doesn't support event emitters, ChildProcess or other kinds of Node.js streams (unless they also happen to be promises or observables). If you need support for these, use async-done.

EXPORTS

asyncAny (default)

Signature:

  • asyncAny(task: (done: Errback) ⇒ Promise|Observable|void, callback: Errback) ⇒ void
  • asyncAny(task: (done: Errback) ⇒ Promise|Observable|void) ⇒ Promise
function runTask (task) {
    asyncAny(task, (error, result) => {
        if (!error) console.log('got result:', result)
    })
}

// or

async function runTask (task) {
    let result = await asyncAny(task)
    console.log('got result:', result)
}

Takes an asynchronous task (function) and a callback. The task is passed a done "errorback" function which can be used to signal completion. Alternatively, the task can return a promise or an observable and will be deemed complete when that "future" succeeds or fails.

Once the task has completed, its error/result is forwarded to the callback. If the callback is omitted, a promise is returned, which is fulfilled/rejected by the corresponding result/error.

If the task returns a value which is both a promise and an observable, it is treated as a promise.

DEVELOPMENT

NPM Scripts

The following NPM scripts are available:

  • test - lint the codebase, compile the library, and run the test suite

Gulp Tasks

The following Gulp tasks are available:

  • build - compile the library and save it to the target directory
  • clean - remove the target directory and its contents
  • default - run the lint and build tasks
  • dump:config - print the build config settings to the console
  • lint - check and report style and usage errors in the gulpfile, source file(s) and test file(s)

SEE ALSO

VERSION

1.0.0

AUTHOR

chocolateboy

Copyright © 2018 by chocolateboy.

This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.

Keywords

FAQs

Package last updated on 04 Jun 2018

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