Created
April 10, 2025 19:26
-
-
Save zephraph/5da168435e2a68bdcd425075800ecf1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function fetch(...[input, init]: FetchParams): Operation<Response> { | |
return action((resolve, reject) => { | |
const internalController = new AbortController(); | |
const signal = internalController.signal; | |
if (init?.signal) { | |
init.signal.addEventListener("abort", () => internalController.abort()); | |
} | |
try { | |
globalThis.fetch(input, { ...init, signal }).then(resolve, reject); | |
} catch (error) { | |
reject(error instanceof Error ? error : new Error(String(error))); | |
} | |
return () => internalController.abort(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment