Replies: 1 comment
-
If you want services to be restarted, the best thing to do would be to try an event sourcing approach instead: https://codesandbox.io/s/event-sourcing-example-xe952?file=/src/index.js // Example: you can use localStorage instead
const persistedEvents = localStorage.getItem('events');
const service = interpret(machine)
.onTransition(state => {
if (state.changed !== undefined) {
// push event to local storage
}
});
service.start();
// replay events
persistedEvents.forEach(event => {
service.send(event);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a parent machine that invokes a child machine in one of the states. When the child machine throws an exception in one of its states, the
onChange
method on the interpreter on the parent machine willstop
the machine, and theonStop
method will persist the serialized state.When I want to retry at a later time, I would like to restore this serialized state and restart the child machine at where it errors out. How can I do this?
restartedService.send('START')
doesn't seem to invoke the child machine again.I noticed I could call
resolvedState.children.pendingOrder
, but thenresolvedState.children.orderMachine.send({ type: 'START' })
results in an error:TypeError: resolvedState.children.orderMachine.send is not a function
serviceRestarted.children
returns an empty map.Can I get some advice on how to get a hold of the child machine, figure out where it threw an error, and restart the parent and child machine at that point?
I can do this pretty easily as a hierarchical state machine, but I'm trying to explore doing it via a parent/child machine relationships, because I think that's more sustainable in the long term to future proof against heavily nested hierarchical state machines.
Beta Was this translation helpful? Give feedback.
All reactions