1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00
Files
nttgin-BGPalerter/src/utils/pubSub.js
Massimo Candela 91f0d03f2a proxy support (#234)
Introduced proxy support

Co-authored-by: Florian Domain <f.domain@criteo.com>
2020-05-26 14:50:16 +02:00

22 lines
560 B
JavaScript

export default class PubSub{
constructor() {
this.callbacks = {};
};
subscribe(channel, callback) {
this.callbacks[channel] = this.callbacks[channel] || [];
this.callbacks[channel].push(callback);
};
publish(channel, content) {
const callbacks = this.callbacks[channel] || [];
for (let clb of callbacks) {
new Promise(function(resolve, reject){
clb(channel, content);
resolve(true);
})
.catch(console.log);
}
};
}