Created
September 4, 2020 20:32
-
-
Save kerimdzhanov/c6b077deba12d0c3da3cb9f6f2739cc7 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 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