From d0d6530aab1ddf472d86afc9159d4e97f3718a00 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 Jan 2024 11:50:51 -0800 Subject: [PATCH] Refactor magickEvent.ts to improve state synchronization and event handling --- .../server/grimoire/src/lib/nodes/magickEvent.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/server/grimoire/src/lib/nodes/magickEvent.ts b/packages/server/grimoire/src/lib/nodes/magickEvent.ts index 8b0e95cf9f..a18365bc4a 100644 --- a/packages/server/grimoire/src/lib/nodes/magickEvent.ts +++ b/packages/server/grimoire/src/lib/nodes/magickEvent.ts @@ -151,16 +151,13 @@ export function makeMagickEventNodeDefinition< completedListener: CommitArgs[1] ) => { const stateService = getDependency('IStateService') - - if (!stateService) { - commit(outflowName, completedListener) - return - } + const eventStore = getDependency('IEventStore') commit(outflowName, async resolveSockets => { // When the event is done, we sync the state and clear it // This sets the state for the next run of this event on this or another engine - await stateService.syncAndClearState() + if (stateService) await stateService.syncAndClearState() + if (eventStore) eventStore.done() completedListener?.(resolveSockets) }) @@ -206,7 +203,8 @@ export function makeMagickEventNodeDefinition< await stateService.rehydrateState(engine!.nodes, stateKey) } - eventConfig.handleEvent(event, newArgs) // Pass all init args and the event to the callback + // Pass all init args and the event to the callback + eventConfig.handleEvent(event, newArgs) if (!node || !engine) return // This allows us to send up the signal that the event node has been triggered by the listener