diff --git a/src/index.ts b/src/index.ts index 1e12ad6..137ac50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,7 +35,7 @@ export default class AbortablePromise implements Promise { on_abort?: () => Promise | void ): Promise { console.log("await_or_abort", promise); - if (promise instanceof AbortablePromise && !on_abort) { + if (AbortablePromise.isAbortable(promise) && !on_abort) { on_abort = async () => promise.abort(); } if (on_abort === undefined) { @@ -82,6 +82,10 @@ export default class AbortablePromise implements Promise { this.emitter = emitter; } + static isAbortable(o: unknown): o is AbortablePromise { + return (o as { abort: boolean }).abort; + } + abort() { this.emitter.abort(); }