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", "license": "ISC",
"dependencies": { "dependencies": {
"@types/node": "^14.14.19", "@types/node": "^14.14.19",
"emittery": "^0.8.0" "emittery": "^0.8.1"
}, },
"devDependencies": { "devDependencies": {
"typescript": "^4.1.3" "typescript": "^4.1.3"

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

Loading…
Cancel
Save