@eventstore.net/event.store
Version:
A simple and fast EventStore that support multiple persistence and notification providers
36 lines • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A Publisher that handle all the data in memory. It is a very simple implementation that should be used
* only for development and test purposes.
*/
class InMemoryPublisher {
constructor() {
this.listeners = new Map();
}
async publish(message) {
const aggregationListeners = this.listeners.get(message.stream.aggregation);
let notified = false;
if (aggregationListeners != null && aggregationListeners.length) {
notified = true;
aggregationListeners.forEach(subscriber => subscriber(message));
}
return notified;
}
async subscribe(aggregation, subscriber) {
let aggregateListeners = this.listeners.get(aggregation);
if (!aggregateListeners) {
aggregateListeners = new Array();
this.listeners.set(aggregation, aggregateListeners);
}
aggregateListeners.push(subscriber);
return {
remove: async () => {
const index = aggregateListeners.indexOf(subscriber);
aggregateListeners.splice(index, 1);
}
};
}
}
exports.InMemoryPublisher = InMemoryPublisher;
//# sourceMappingURL=memory.js.map