@schibsted/niche-utils
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -1,1 +0,1 @@ | ||
export declare const fetchWrapper: <T>(url: string, options?: RequestInit, timeout?: number) => Promise<T>; | ||
export declare const fetchWrapper: <T>(url: string, options?: RequestInit, timeout?: number, timeoutCallback?: () => void) => Promise<T>; |
@@ -11,10 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { FetchError } from './fetchError'; | ||
export const fetchWrapper = (url, options, timeout) => __awaiter(void 0, void 0, void 0, function* () { | ||
export const fetchWrapper = (url, options, timeout, timeoutCallback) => __awaiter(void 0, void 0, void 0, function* () { | ||
let signal; | ||
if (timeout) { | ||
const controller = new AbortController(); | ||
signal = controller.signal; | ||
setTimeout(() => { | ||
controller.abort(); | ||
}, timeout); | ||
signal = AbortSignal.timeout(timeout); | ||
if (timeoutCallback) { | ||
signal.onabort = timeoutCallback; | ||
} | ||
} | ||
@@ -21,0 +20,0 @@ const response = yield fetch(url, Object.assign(Object.assign({}, options), { signal })); |
{ | ||
"name": "@schibsted/niche-utils", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"repository": { | ||
@@ -28,3 +28,3 @@ "type": "git", | ||
}, | ||
"gitHead": "53e12e9bf4ccd6839a4a198b0a4d66baf2ea8145" | ||
"gitHead": "90c2c4d7b72a8d3c5afd1444b318e08795cb6ae1" | ||
} |
import { FetchError } from './fetchError'; | ||
export const fetchWrapper = async <T>(url: string, options?: RequestInit, timeout?: number): Promise<T> => { | ||
export const fetchWrapper = async <T>( | ||
url: string, | ||
options?: RequestInit, | ||
timeout?: number, | ||
timeoutCallback?: () => void | ||
): Promise<T> => { | ||
let signal: AbortSignal | undefined; | ||
if (timeout) { | ||
const controller = new AbortController(); | ||
signal = controller.signal; | ||
setTimeout(() => { | ||
controller.abort(); | ||
}, timeout); | ||
signal = AbortSignal.timeout(timeout); | ||
if (timeoutCallback) { | ||
signal.onabort = timeoutCallback; | ||
} | ||
} | ||
@@ -13,0 +18,0 @@ |
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
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
17829
471