Hi there,
I'm running into a problem with sodium::switch_s
: My code is structured practically identical to the dynamically adding and removing characters example from the book (listing 7.8), except that the child processes emit only two streams, sDestroy
and sRequest
. The latter is similar to sBite
from the book, except that sub-streams are merged with sodium::merge
instead of mergeToSet
. Child processes get passed the stream sCreate
(from which sAdd
is derived) and need to emit an initial "request" event that is defined like
// Pseudo C++
sInit = sCreate.once().map(_ -> makeInitRequest());
sRequest = merge({ sInit, ... }, Request::append);
The problem is that this first request is never emitted, which seems to be expected behaviour according to the comment in sodium::switch_s
. When I add defer()
to sAdd
and pass the non-deferred sCreate
to the sub-processes, it seems to work, but I'm not sure whether using defer
implies corner cases that could lead to a missing initial event again. The code for the sub-processes also works as expected when testing it in isolation outside of the switch.
Is there a way to emit the initial event without using defer
?
Thanks,
Stefan
PS: Sorry, I can't post the code but if needed I can try to produce a minimal example that demonstrates my issue.