Skip to content

Instantly share code, notes, and snippets.

View kaskar2008's full-sized avatar
😐
Rly?

Karen kaskar2008

😐
Rly?
View GitHub Profile
@Raiondesu
Raiondesu / AbortableFetch.ts
Last active December 2, 2023 13:20
A simple and usable abortable web (fetch, promise) realization in TypeScript
import AbortablePromise from './abortablePromise';
export default function abortableFetch(input?: string | Request, init?: RequestInit) {
const signal = init ? init.signal : input ? input['signal'] : undefined;
const abortController = signal ? undefined : new AbortController();
const promise = new AbortablePromise<Response>(fetch.apply(arguments), abortController);
if (signal) {
promise.signal = signal;