npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

async-any

v1.0.0

Published

Manage various forms of asynchronous completion in a uniform way

Downloads

21

Readme

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 AND LICENSE

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.