hypershield
Version:
Middleware suite for high-performance and resilient APIs
23 lines • 680 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventBus = void 0;
class EventBus {
constructor() {
this.handlers = new Map();
}
subscribe(event, handler) {
var _a;
if (!this.handlers.has(event)) {
this.handlers.set(event, []);
}
(_a = this.handlers.get(event)) === null || _a === void 0 ? void 0 : _a.push(handler);
}
publish(event, data) {
const eventHandlers = this.handlers.get(event);
if (eventHandlers) {
eventHandlers.forEach(handler => handler(data));
}
}
}
exports.EventBus = EventBus;
//# sourceMappingURL=eventBus.js.map