|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import Emittery from "emittery";
|
|
|
|
|
import { promisify } from "util";
|
|
|
|
|
|
|
|
|
|
//needed to pass information on wether or not the promise has been aborted witout 'this'
|
|
|
|
|
class AbortableEmittery extends Emittery {
|
|
|
|
@ -11,19 +10,22 @@ class AbortableEmittery extends Emittery {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AbortablePromise<T> extends Promise<T | null> {
|
|
|
|
|
export default class AbortablePromise<T> extends Promise<T | null> {
|
|
|
|
|
private emitter: AbortableEmittery;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
make_generator: (
|
|
|
|
|
await_or_abort: (
|
|
|
|
|
promise: Promise<any>,
|
|
|
|
|
on_abort: () => void
|
|
|
|
|
) => Promise<void>
|
|
|
|
|
on_abort: () => Promise<unknown>
|
|
|
|
|
) => Promise<unknown>
|
|
|
|
|
) => AsyncGenerator
|
|
|
|
|
) {
|
|
|
|
|
const emitter = new AbortableEmittery();
|
|
|
|
|
const await_or_abort = (promise: Promise<any>, on_abort: () => void) => {
|
|
|
|
|
const await_or_abort = (
|
|
|
|
|
promise: Promise<any>,
|
|
|
|
|
on_abort: () => Promise<unknown>
|
|
|
|
|
) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let resolved = false;
|
|
|
|
|
emitter.on("abort", () => {
|
|
|
|
|