Ghost/ghost/domain-events
Simon Backx 913ad18b71
Added DomainEvents.allSettled utility method (#16075)
no issue

With the increased usage of DomainEvents, it gets harder to build
reliable tests without having to resort to timeouts. This utility method
allows us to wait for all events to be processed before continuing with
the test.

This change should speed up tests and make them more reliable.

It only adds extra code when running tests and shouldn't impact
production.
2023-01-04 14:30:35 +01:00
..
lib Added DomainEvents.allSettled utility method (#16075) 2023-01-04 14:30:35 +01:00
test Added DomainEvents.allSettled utility method (#16075) 2023-01-04 14:30:35 +01:00
.eslintrc.js
index.js
package.json Added DomainEvents.allSettled utility method (#16075) 2023-01-04 14:30:35 +01:00
README.md

Domain Events

Usage

const DomainEvents = require('@tryghost/domain-events');

class MyEvent {
    constructor(message) {
        this.timestamp = new Date();
        this.data = {
            message
        };
    }
}

DomainEvents.subscribe(MyEvent, function handler(event) {
    console.log(event.data.message);
});

const event = new MyEvent('hello world');

DomainEvents.dispatch(event);