timeout-signal
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -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; |
25
index.js
@@ -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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
0
Yes
2985
29
35
- Removedabort-controller@^3.0.0
- Removedabort-controller@3.0.0(transitive)
- Removedevent-target-shim@5.0.1(transitive)