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

@smithy/abort-controller

Package Overview
Dependencies
Maintainers
0
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/abort-controller

A simple abort controller library

  • 3.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
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 09 Dec 2024

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