Better is abortable checker

master
Kuba Orlik 4 years ago
parent 25862a998c
commit 3d13153184

@ -35,7 +35,7 @@ export default class AbortablePromise<T> implements Promise<T | null> {
on_abort?: () => Promise<unknown> | void on_abort?: () => Promise<unknown> | void
): Promise<L | null> { ): Promise<L | null> {
console.log("await_or_abort", promise); console.log("await_or_abort", promise);
if (promise instanceof AbortablePromise && !on_abort) { if (AbortablePromise.isAbortable(promise) && !on_abort) {
on_abort = async () => promise.abort(); on_abort = async () => promise.abort();
} }
if (on_abort === undefined) { if (on_abort === undefined) {
@ -82,6 +82,10 @@ export default class AbortablePromise<T> implements Promise<T | null> {
this.emitter = emitter; this.emitter = emitter;
} }
static isAbortable(o: unknown): o is AbortablePromise<unknown> {
return (o as { abort: boolean }).abort;
}
abort() { abort() {
this.emitter.abort(); this.emitter.abort();
} }

Loading…
Cancel
Save