Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
abort-controller
Advanced tools
The abort-controller npm package provides a way to abort one or more Web API tasks, such as fetch requests, by using an AbortController object. This package is a polyfill for the AbortController interface based on the WHATWG Fetch specification, which allows you to cancel tasks by calling the abort() method on the controller instance.
Creating an AbortController instance
This feature allows you to create a new instance of AbortController, which can be used to generate a signal that can be passed to fetch or other APIs that support aborting.
const AbortController = require('abort-controller');
const controller = new AbortController();
const signal = controller.signal;
Aborting a fetch request
This code sample demonstrates how to use the AbortController to abort an ongoing fetch request. The signal is passed to the fetch call, and the request can be aborted by calling the abort() method on the controller.
const fetch = require('node-fetch');
const AbortController = require('abort-controller');
const controller = new AbortController();
const signal = controller.signal;
fetch('https://example.com', { signal })
.then(response => response.json())
.catch(err => {
if (err.name === 'AbortError') {
console.log('Fetch aborted');
} else {
console.error('Fetch error:', err);
}
});
// Abort the request
controller.abort();
The p-cancelable package provides a way to create cancelable promises. It is similar to abort-controller in that it allows you to cancel asynchronous tasks, but it works by wrapping promises rather than using a signal-based approach.
Bluebird is a fully-featured promise library that includes support for cancellation. It is more comprehensive than abort-controller as it provides a full promise implementation with additional features like map, reduce, and filter for promises, but it also includes the ability to cancel promises.
Axios is a promise-based HTTP client for the browser and Node.js that includes a cancellation feature. While abort-controller is focused on providing an AbortController polyfill, axios offers a broader set of HTTP client features, including the ability to cancel requests using a CancelToken.
An implementation of WHATWG AbortController interface.
import AbortController from "abort-controller"
const controller = new AbortController()
const signal = controller.signal
signal.addEventListener("abort", () => {
console.log("aborted!")
})
controller.abort()
Use npm to install then use a bundler.
npm install abort-controller
Or download from dist
directory.
import AbortController from "abort-controller"
// or
const AbortController = require("abort-controller")
// or UMD version defines a global variable:
const AbortController = window.AbortControllerShim
The AbortSignal object which is associated to this controller.
Notify abort
event to listeners that the signal
has.
Contributing is welcome ❤️
Please use GitHub issues/PRs.
npm install
installs dependencies for development.npm test
runs tests and measures code coverage.npm run clean
removes temporary files of tests.npm run coverage
opens code coverage of the previous test with your default browser.npm run lint
runs ESLint.npm run build
generates dist
codes.npm run watch
runs tests on each file change.FAQs
An implementation of WHATWG AbortController interface.
The npm package abort-controller receives a total of 15,468,797 weekly downloads. As such, abort-controller popularity was classified as popular.
We found that abort-controller demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.