🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

@smithy/abort-controller

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/abort-controller

A simple abort controller library

4.0.4
latest
Version published
Weekly downloads
23M
-16.95%
Maintainers
3
Weekly downloads
 
Created

What is @smithy/abort-controller?

@smithy/abort-controller is a package that provides an implementation of the AbortController interface, which is used to signal that an operation should be aborted. This is particularly useful for managing and controlling asynchronous operations, such as HTTP requests, in a more efficient manner.

What are @smithy/abort-controller's main functionalities?

Creating an AbortController

This feature allows you to create an instance of AbortController and obtain its associated signal. The signal can then be passed to any operation that supports aborting.

const { AbortController } = require('@smithy/abort-controller');
const controller = new AbortController();
const signal = controller.signal;

Aborting an Operation

This feature demonstrates how to use the AbortController to abort an ongoing asynchronous operation. The operation checks if the signal is aborted and listens for the abort event to handle the abortion.

const { AbortController } = require('@smithy/abort-controller');
const controller = new AbortController();
const signal = controller.signal;

// Simulate an asynchronous operation
const fetchData = (signal) => {
  return new Promise((resolve, reject) => {
    if (signal.aborted) {
      return reject(new Error('Operation aborted'));
    }
    setTimeout(() => resolve('Data fetched'), 1000);
    signal.addEventListener('abort', () => reject(new Error('Operation aborted')));
  });
};

fetchData(signal).catch(err => console.error(err.message));

// Abort the operation after 500ms
setTimeout(() => controller.abort(), 500);

Other packages similar to @smithy/abort-controller

FAQs

Package last updated on 29 May 2025

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