@effection/events
Advanced tools
Comparing version 0.6.0 to 0.6.1-a8ad962
export { once } from './once'; | ||
export { on, Subscription } from './on'; | ||
export { throwOnErrorEvent } from './throw-on-error-event'; | ||
export { EventSource } from './event-source'; |
@@ -8,10 +8,15 @@ "use strict"; | ||
*/ | ||
function once(source, eventName) { | ||
return ({ resume, ensure }) => { | ||
let listener = (...args) => resume(args); | ||
ensure(() => event_source_1.removeListener(source, eventName, listener)); | ||
event_source_1.addListener(source, eventName, listener); | ||
}; | ||
function* once(source, eventName) { | ||
let onceListener; | ||
try { | ||
return yield new Promise((resolve) => { | ||
onceListener = (...args) => resolve(args); | ||
event_source_1.addListener(source, eventName, onceListener); | ||
}); | ||
} | ||
finally { | ||
event_source_1.removeListener(source, eventName, onceListener); | ||
} | ||
} | ||
exports.once = once; | ||
//# sourceMappingURL=once.js.map |
{ | ||
"name": "@effection/events", | ||
"version": "0.6.0", | ||
"version": "0.6.1-a8ad962", | ||
"description": "Helpers for listening to events with effection", | ||
@@ -17,3 +17,2 @@ "main": "dist/index.js", | ||
"test": "mocha -r ts-node/register test/**/*.test.ts", | ||
"pack:publish": "npm publish $*", | ||
"prepack": "tsc --outdir dist --project tsconfig.dist.json --declaration --sourcemap --module commonjs", | ||
@@ -20,0 +19,0 @@ "mocha": "mocha -r ts-node/register" |
Sorry, the diff of this file is not supported yet
10426
18
129