Erik Dreyer
03/23/2023, 1:10 AMsuspend fun <E: Event> dispatch(command: Command): Effect<WorkflowError, E> {
log.debug("BEFORE EFFECT")
return effect {
log.debug("START EFFECT")
ensureNotNull(commandHandlers[command::class]) {
MissingHandler("No handler for command $command")
}.let {
it.invoke(command) as E
}
}
}
The signature of the invoke
method, if this helps:
context(EffectScope<WorkflowError>)
final override suspend fun invoke(request: R): E {
Log output:
2023-03-22T21:07:07.106-04:00 DEBUG 38879 --- [-5 @coroutine#7] i.l.common.workflow.WorkflowDispatcher : BEFORE EFFECT
2023-03-22T21:07:07.107-04:00 DEBUG 38879 --- [-5 @coroutine#7] i.l.common.workflow.WorkflowDispatcher : START EFFECT
...
2023-03-22T21:07:07.175-04:00 DEBUG 38879 --- [-3 @coroutine#7] i.l.common.workflow.WorkflowDispatcher : START EFFECT
Youssef Shoaib [MOD]
03/23/2023, 7:49 AMErik Dreyer
03/23/2023, 1:47 PMEither
to Effect
and a side effect (no pun intented) of that is that fold
was being called twice. For Either
this is fine, but for Effect
it runs the process twice.Youssef Shoaib [MOD]
03/23/2023, 2:15 PMErik Dreyer
03/23/2023, 2:16 PM