Skip to content

Commit

Permalink
Support for an async decide / handle function for CommandHandler (
Browse files Browse the repository at this point in the history
#99)

* async decider for command handler

* formatting

---------

Co-authored-by: Oskar Dudycz <[email protected]>
  • Loading branch information
alex-laycalvert and oskardudycz authored Oct 11, 2024
1 parent 84dd2ae commit 3f1c6c4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/packages/emmett/src/commandHandling/handleCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ export const CommandHandler =
async <Store extends EventStore<StreamVersion>>(
store: Store,
id: string,
handle: (state: State) => StreamEvent | StreamEvent[],
handle: (
state: State,
) =>
| StreamEvent
| StreamEvent[]
| Promise<StreamEvent>
| Promise<StreamEvent[]>,
handleOptions?: HandleOptions<StreamVersion, EventStore<StreamVersion>>,
): Promise<CommandHandlerResult<State, StreamEvent, StreamVersion>> =>
asyncRetry(
Expand Down Expand Up @@ -116,7 +122,7 @@ export const CommandHandler =
const currentStreamVersion = aggregationResult.currentStreamVersion;

// 3. Run business logic
const result = handle(state);
const result = await handle(state);

const newEvents = Array.isArray(result) ? result : [result];

Expand Down

0 comments on commit 3f1c6c4

Please sign in to comment.