Skip to content

Instantly share code, notes, and snippets.

@tom-sherman
Created October 9, 2023 13:58
Show Gist options
  • Save tom-sherman/10079cf614d9aaf1dd857dbe13bfa101 to your computer and use it in GitHub Desktop.
Save tom-sherman/10079cf614d9aaf1dd857dbe13bfa101 to your computer and use it in GitHub Desktop.
function wrapWithSignal(ms, fn) {
const signal = AbortSignal.timeout(ms)
return fn(signal)
}
function foo() {
return wrapWithSignal(signal => fetch("/", {signal}))
}
try {
await foo()
} catch (e) {
console.error(e.message)
console.error(e.stack)
}
Result is:
VM2225:4 Failed to execute 'timeout' on 'AbortSignal': Value is not of type 'unsigned long long'.
(anonymous) @ VM2225:4
VM2225:5 TypeError: Failed to execute 'timeout' on 'AbortSignal': Value is not of type 'unsigned long long'.
at wrapWithSignal (<anonymous>:2:32)
at foo (<anonymous>:2:12)
at <anonymous>:2:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment