Type corrections

master
Kuba Orlik 4 years ago
parent 6fa61a7107
commit e751b8fff8

4
.gitignore vendored

@ -0,0 +1,4 @@
/@types/
/lib/
/node_modules/
/package-lock.json

@ -15,7 +15,7 @@
"license": "ISC",
"dependencies": {
"@types/node": "^14.14.19",
"emittery": "^0.8.0"
"emittery": "^0.8.1"
},
"devDependencies": {
"typescript": "^4.1.3"

@ -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", () => {

Loading…
Cancel
Save