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

all-aboard

v2.0.1

Published

Perform parallel and/or sequential asynchronous tasks with ease

Downloads

10

Readme

A small Javascript library to perform parallel and/or sequential asynchronous tasks with ease.

Installation

yarn add all-aboard
npm install all-aboard

Upgrade

yarn upgrade all-aboard --latest

For more information, please refer to the yarn documentation.

npm update all-aboard

For more information, please refer to the npm documentation.

Usage

Sequence

The sequence function allows you to run asynchronous functions in order, one after the other, before proceeding on the main thread. Each asynchronous function is executed in incremental order, meaning that tasks[0] runs first, tasks[1] after that, and so on.

Uniquely to the sequence function, you have the option to be ejected back on the main thread if any of the asynchronous tasks are rejected. This means that if a task throws an error in the middle, the sequence function will not continue to run the remaining tasks.

Structure

const response = await sequence(tasks[], arguments[], eject);

Example

const { sequence } = require('all-aboard');

const arr = [async1, async2, async3];

(async () => {
  await sequence(arr, ['shared', 'arguments'], true);
})();

Parallel

The parallel function allows you to run asynchronous functions in parallel, non-blocking behavior, before proceeding on the main thread. Each asynchronous function will be executed as soon as possible, but the main thread will not proceed until each promise has been settled.

Structure

const response = await parallel(tasks[], arguments[]);

Example

const { parallel } = require('all-aboard');

(async () => {
  await parallel(() => asyncFunc('with argument'), asyncFunc);
})();

Arguments

If you want to run an asynchronous function without passing any arguments, you can pass the function as a task to the sequence or parallel function.

await parallel(asyncFunc);

Specific

Things become more tricky if you want to run an asynchronous function with some passed arguments. In that case, you need to either:

  1. Wrap the asynchronous function in an anonymous function.
await sequence(() => asyncFunc('foo'));
  1. Bind the desired arguments to the passed asynchronous function.
await parallel(asyncFunc.bind(this, 'bar', 'baz'));

Shared

You might come across a use case where you would like to pass the same arguments to each asynchronous function in your tasks. Instead of repeating yourself, you can pass all shared arguments to the sequence or parallel function by passing them in an array after the tasks argument.

await sequence(asyncFuncArr, ['foo', 'bar']);

Please note that shared arguments can be overwritten by specific arguments

Response

Each response contains a promise summary of each executed task. If the status is fulfilled, the object will contain a value property containing the returned value from the successful task. If the status has been rejected, the object will instead contain a reason property with thrown error from the unsuccessful task.

[
  { status: 'fulfilled', value: undefined },
  { status: 'fulfilled', value: 'returned value' },
  { status: 'rejected', reason: 'thrown error' }
];

Uninstall

yarn remove all-aboard
npm uninstall all-aboard