@webiny/pubsub
Advanced tools
Comparing version 5.17.0-beta.0 to 5.17.0-beta.1
18
index.js
@@ -10,2 +10,16 @@ "use strict"; | ||
const subscribers = []; | ||
const withUnsubscribe = cb => { | ||
const once = async event => { | ||
await cb(event); | ||
const index = subscribers.findIndex(fn => fn === once); | ||
if (index > -1) { | ||
subscribers.splice(index, 1); | ||
} | ||
}; | ||
return once; | ||
}; | ||
return { | ||
@@ -20,2 +34,6 @@ getTopicName() { | ||
subscribeOnce(cb) { | ||
subscribers.push(withUnsubscribe(cb)); | ||
}, | ||
getSubscribers() { | ||
@@ -22,0 +40,0 @@ return subscribers; |
{ | ||
"name": "@webiny/pubsub", | ||
"version": "5.17.0-beta.0", | ||
"version": "5.17.0-beta.1", | ||
"main": "index.js", | ||
@@ -22,4 +22,4 @@ "repository": { | ||
"@babel/runtime": "^7.5.5", | ||
"@webiny/cli": "^5.17.0-beta.0", | ||
"@webiny/project-utils": "^5.17.0-beta.0", | ||
"@webiny/cli": "^5.17.0-beta.1", | ||
"@webiny/project-utils": "^5.17.0-beta.1", | ||
"rimraf": "^3.0.2", | ||
@@ -33,3 +33,3 @@ "ttypescript": "^1.5.12", | ||
}, | ||
"gitHead": "4b43404bf5ed84250bc9e3e5a64cc80501ae7e34" | ||
"gitHead": "481d1db1aaff389b86d8a220b99bd3ff4d9cd4a0" | ||
} |
@@ -8,4 +8,5 @@ export interface Subscriber<TEvent> { | ||
subscribe(cb: (event: TEvent) => void | Promise<void>): void; | ||
subscribeOnce(cb: (event: TEvent) => void | Promise<void>): void; | ||
getSubscribers(): Subscriber<TEvent>[]; | ||
publish(event?: TEvent): Promise<void>; | ||
publish(event?: TEvent): Promise<any>; | ||
} |
Sorry, the diff of this file is not supported yet
6391
55