Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export class CancellableRequest {
private controller = new AbortController();
public fetch(input: RequestInfo, init: RequestInit = {}): Promise<Response> {
init.signal = this.controller.signal;
return fetch(input, init)
.then(res => res.json());
}
public isCancelled(): boolean {
return this.controller.signal.aborted;
}
public cancel(): void {
this.controller.abort();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.