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

abort-controller

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abort-controller

An implementation of WHATWG AbortController interface.

  • 3.0.0
  • next
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20M
decreased by-4.1%
Maintainers
1
Weekly downloads
 
Created

What is abort-controller?

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.

What are abort-controller's main functionalities?

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();

Other packages similar to abort-controller

Keywords

FAQs

Package last updated on 30 Mar 2019

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