mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
22 lines
560 B
JavaScript
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);
|
|
}
|
|
};
|
|
|
|
} |