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

timeout-signal

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timeout-signal - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

license

58

index.d.ts

@@ -1,48 +0,20 @@

import { AbortSignal } from "abort-controller"
/**
Create an AbortSignal that aborts after a delay.
declare const timeoutSignal: {
/**
Create an AbortSignal that aborts after a delay.
@param timeout The milliseconds to wait.
@example
```
const timeoutSignal = require("timeout-signal");
const fetch = require("cross-fetch");
@param timeout - The milliseconds to wait.
try {
const response = await fetch("https://www.google.com", { signal: timeoutSignal(5000) })
// Handle response
} catch (error) {
if (error.message === "The user aborted a request.") {
// Handle abortion
}
}
```
*/
(timeout: number): AbortSignal
@example
```
import timeoutSignal from 'timeout-signal';
/**
The signal to clear the timeout for.
@param signal The signal to clear the timeout for.
@example
```
const timeoutSignal = require("timeout-signal");
const fetch = require("cross-fetch");
const signal = timeoutSignal(5000)
try {
const response = await fetch("https://www.google.com", { signal })
timeoutSignal.clear(signal)
// Handle response
} catch (error) {
if (error.message === "The user aborted a request.") {
// Handle abortion
}
try {
const response = await fetch('https://www.google.com', {signal: timeoutSignal(5000)});
// Handle response
} catch (error) {
if (signal.aborted) {
// Handle abortion
}
```
*/
clear(signal: AbortSignal): void
}
export = timeoutSignal
```
*/
export default function timeoutSignal(timeout: number): AbortSignal;

@@ -1,25 +0,16 @@

"use strict"
const { AbortController } = require("abort-controller")
const signalMap = new WeakMap()
module.exports = timeout => {
export default function timeoutSignal(timeout) {
if (!Number.isInteger(timeout)) {
throw new TypeError(`Expected an integer, got ${typeof timeout}`)
throw new TypeError('Expected an integer');
}
const controller = new AbortController()
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort()
}, timeout)
controller.abort();
}, timeout);
signalMap.set(controller.signal, timeoutId)
// Allow Node.js processes to exit early if only the timeout is running
timeoutId?.unref?.();
return controller.signal
return controller.signal;
}
module.exports.clear = signal => {
clearTimeout(signalMap.get(signal))
}
{
"name": "timeout-signal",
"version": "1.1.0",
"description": "Create an AbortSignal that aborts after a delay.",
"repository": "https://github.com/node-fetch/timeout-signal.git",
"author": "Richie Bendall <richiebendall@gmail.com>",
"version": "2.0.0",
"description": "Create an AbortSignal that aborts after a delay",
"license": "MIT",
"main": "index.js",
"repository": "node-fetch/timeout-signal",
"author": {
"name": "Richie Bendall",
"email": "richiebendall@gmail.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=16"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [

@@ -13,9 +23,2 @@ "index.js",

],
"engines": {
"node": ">=10"
},
"scripts": {
"lint": "xo",
"test": "xo && ava"
},
"keywords": [

@@ -26,18 +29,9 @@ "timeout",

],
"dependencies": {
"abort-controller": "^3.0.0"
},
"devDependencies": {
"ava": "^3.8.1",
"delay": "^4.4.0",
"eslint-config-richienb": "^0.4.2",
"p-event": "^4.1.0",
"xo": "^0.30.0"
},
"resolutions": {
"eslint": "^6.8.0"
},
"xo": {
"extends": "richienb"
"ava": "^5.0.1",
"p-event": "^5.0.1",
"time-span": "^5.1.0",
"tsd": "^0.24.1",
"xo": "^0.52.4"
}
}
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