@dxos/async
Advanced tools
Comparing version 1.0.1-alpha.0 to 1.0.2-alpha.0
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export declare function runWithTimeout<T>(action: () => Promise<T>, timeout: number, getError?: () => Error): Promise<T>; | ||
export declare function runWithTimeout<T>(action: () => Promise<T>, timeout: number, error?: Error): Promise<T>; | ||
//# sourceMappingURL=run-with-timeout.d.ts.map |
@@ -10,10 +10,12 @@ "use strict"; | ||
*/ | ||
function runWithTimeout(action, timeout, getError) { | ||
function throwOnTimeout(timeout, getError) { | ||
function runWithTimeout(action, timeout, error) { | ||
// It's important to create this error object here and not inside `setTimeout` callback because this is the place where the stack trace will be captured. | ||
const actualError = error !== null && error !== void 0 ? error : new Error(`Timed out in ${timeout}ms.`); | ||
function throwOnTimeout() { | ||
// eslint-disable-next-line promise/param-names | ||
return new Promise((_, reject) => setTimeout(() => reject(getError()), timeout)); | ||
return new Promise((_, reject) => setTimeout(() => reject(actualError), timeout)); | ||
} | ||
return Promise.race([ | ||
action(), | ||
throwOnTimeout(timeout, getError !== null && getError !== void 0 ? getError : (() => new Error(`Timed out in ${timeout}ms.`))) | ||
throwOnTimeout() | ||
]); | ||
@@ -20,0 +22,0 @@ } |
{ | ||
"name": "@dxos/async", | ||
"version": "1.0.1-alpha.0", | ||
"version": "1.0.2-alpha.0", | ||
"description": "Basic async utils", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
112643
1290