Comparing version 0.0.11 to 0.0.12
@@ -9,6 +9,3 @@ export interface IDefer<T> { | ||
export default function makeDefer<T = void>(): IDefer<T>; | ||
export declare function makeBroadcastStream<T>(): { | ||
[x: number]: () => AsyncIterator<T>; | ||
export interface IBroadcastStream<T> extends AsyncIterable<T> { | ||
listen(onNext: (value: T) => any, {onError, onDone}?: { | ||
@@ -18,5 +15,12 @@ onError?(error: unknown): any; | ||
}): (this: void) => void; | ||
next(value: T): void; | ||
throw(error: unknown): void; | ||
done(): void; | ||
}; | ||
} | ||
export default function makeDefer<T = void>(): IDefer<T>; | ||
export declare function makeBroadcastStream<T>(): IBroadcastStream<T>; |
25
index.js
@@ -1,3 +0,1 @@ | ||
'use strict' | ||
module.exports = function makeDefer() { | ||
@@ -27,5 +25,7 @@ let resolve = undefined | ||
}, | ||
return() { | ||
async return(value) { | ||
return {value: undefined, done: true} | ||
}, | ||
throw() { | ||
async throw(e) { | ||
return {value: undefined, done: true} | ||
} | ||
@@ -50,3 +50,6 @@ } | ||
for (const {onNext} of listeners) | ||
onNext(value) | ||
try { | ||
onNext(value) | ||
} catch { | ||
} | ||
}, | ||
@@ -59,3 +62,6 @@ throw(error) { | ||
for (const {onError} of listeners) | ||
onError === null || onError === void 0 ? void 0 : onError(error) | ||
try { | ||
onError?.(error) | ||
} catch { | ||
} | ||
}, | ||
@@ -66,7 +72,10 @@ done() { | ||
done = true | ||
defer.resolve({done: true}) | ||
defer.resolve({value: undefined, done: true}) | ||
for (const {onDone} of listeners) | ||
onDone === null || onDone === void 0 ? void 0 : onDone() | ||
try { | ||
onDone?.() | ||
} catch { | ||
} | ||
}, | ||
} | ||
} |
{ | ||
"name": "jdefer", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/tranvansang/jdefer", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5438
168