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

abort-group

v1.1.2

Published

Group a set of cancelable actions to be aborted together at any time.

Downloads

4

Readme

abort-group

Group a set of cancelable actions to be aborted together at any time.

Install

npm install --save abort-group

Usage

import abortGroup from "abort-group";

const group = abortGroup();

// Supports all `(set|request)Name` functions off of the window such as:
group.setTimeout(handleAnimationFrame, 1000);
group.setInterval(handleAnimationFrame, 1000);
group.requestAnimationFrame(handleAnimationFrame);

// Supports both nodejs and dom event emitters.
group.on(document.body, "click", handleClick);
group.once(document.body, "DOMContentLoaded", handleLoad);

// Can add cancel functions.
group.add(() => console.log("aborted"));

// Can add objects with a abort, cancel, or unsubscribe functions.
group.add({ abort: () => console.log("aborted") });
group.add({ cancel: () => console.log("aborted") });
group.add({ unsubscribe: () => console.log("aborted") });

// This means you can add other groups which get aborted when the parent does.
const subgroup = abortGroup();
group.add(subgroup);

// You can also add observables.
group.add(Rx.Observable.range(1, 5).subscribe(handleSubscription));

finally

group.abort(); // Stop all async tasks above.

API

#set{NAME}(...args): function

Calls the native set function such as setTimeout, passing all arguments, and clears it if the group is aborted. Returns a function to cancel the task early.

the methods are dynamically added based on what is available

group.setTimeout(() => ..., 500);
group.setInterval(() => ..., 500);
group.setImmediate(() => ...);

const stop = group.setTimeout(() => ..., 100);
stop(); // manually remove the timeout.

#request{NAME}(...args): function

Calls the native request function such as requestAnimationFrame, passing all arguments, and cancels it if the group is aborted.

the methods are dynamically added based on what is available

group.requestAnimationFrame(() => ...);
group.requestIdleCallback(() => ...);

const stop = group.requestAnimationFrame(() => ...);
stop(); // manually remove the animation frame.

#on(emitter: EventEmitter|EventTarget, type: string, handler: function): function

Adds an event handler to the provided nodejs EventEmitter or browser EventTarget and removes the handler if the group is aborted. Returns a function to cancel the handler early.

const stop = group.on(window, "resize", handleResize);
stop(); // manually stop the event handler.

#once(emitter: EventEmitter|EventTarget, type: string, handler: function): function

Adds an event handler to the provided nodejs EventEmitter or browser EventTarget and removes the handler if the group is aborted or after the first call.

const stop = group.once(window, "resize", handleResize); // Only handle one resize.
stop(); // manually stop the event handler.

#add(cancelable): function

Adds a cancelable object (one with an abort, cancel or unsubscribe method) to be canceled when the group aborts. You can also pass a function to be called when the group aborts.

group.add(handleAbort);
group.add({ abort: handleAbort });
group.add({ cancel: handleAbort });
group.add({ unsubscribe: handleAbort });

const stop = group.add(handleAbort);
stop(); // manually call the handleAbort function.

#fork(): AbortGroup

Creates a new group which is automatically aborted then the parent group is aborted.

const subGroup = group.fork();
subGroup.setTimeout(() => ..., 100);
group.abort(); // Cancels sub group also.

#abort()

Aborts any tasks added to the group using the above methods.

group.abort();