Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jdefer

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jdefer - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

11

index.d.ts

@@ -10,1 +10,12 @@ export interface IDefer<T> {

export default function makeDefer<T = void>(): IDefer<T>;
export declare function makeBroadcastStream<T>(): {
[x: number]: () => AsyncIterator<T>;
listen(onNext: (value: T) => any, {onError, onDone}?: {
onError?(error: unknown): any;
onDone?(): any;
}): (this: void) => void;
next(value: T): void;
throw(error: unknown): void;
done(): void;
};

@@ -16,1 +16,54 @@ 'use strict'

}
module.exports.makeBroadcastStream = function makeBroadcastStream() {
const listeners = []
let done = false
let defer = makeDefer()
return {
[Symbol.asyncIterator]() {
return {
next() {
return defer.promise
},
return() {
},
throw() {
}
}
},
listen(onNext, {onError, onDone} = {}) {
if (done)
throw new Error('Cannot listen after done')
const listener = {onNext, onError, onDone}
listeners.push(listener)
return function removeListener() {
const idx = listeners.lastIndexOf(listener)
if (idx >= 0)
listeners.splice(idx, 1)
}
},
next(value) {
if (done)
throw new Error('Cannot next after done')
defer.resolve({value, done: false})
for (const {onNext} of listeners)
onNext(value)
},
throw(error) {
if (done)
throw new Error('Cannot throw after done')
done = true
defer.reject(error)
for (const {onError} of listeners)
onError === null || onError === void 0 ? void 0 : onError(error)
},
done() {
if (done)
throw new Error('Cannot done after done')
done = true
defer.resolve({done: true})
for (const {onDone} of listeners)
onDone === null || onDone === void 0 ? void 0 : onDone()
},
}
}

4

package.json
{
"name": "jdefer",
"version": "0.0.9",
"version": "0.0.10",
"main": "index.js",

@@ -23,4 +23,4 @@ "repository": "https://github.com/tranvansang/jdefer",

],
"author": "Tran Sang <t@sang.jp>",
"author": "Sang Tran <t@sang.jp>",
"license": "MIT"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc