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

22 lines
560 B
JavaScript
Raw Normal View History

export default class PubSub{
constructor() {
this.callbacks = {};
2020-01-12 05:00:32 +01:00
};
subscribe(channel, callback) {
this.callbacks[channel] = this.callbacks[channel] || [];
this.callbacks[channel].push(callback);
2020-01-12 05:00:32 +01:00
};
publish(channel, content) {
2020-01-17 02:01:15 +01:00
const callbacks = this.callbacks[channel] || [];
for (let clb of callbacks) {
new Promise(function(resolve, reject){
clb(channel, content);
resolve(true);
})
.catch(console.log);
}
2020-01-12 05:00:32 +01:00
};
}