Stopping previous actor before spawning new actor with same ID? #3161
Unanswered
lewisl9029
asked this question in
Q&A
Replies: 1 comment 3 replies
-
If you add
This would essentially be the same as this: [event.id]: spawn(updateMachine.withContext({/* custom initial context */}), event.id) And you can read from both the parent's |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there!
I've been working on a file-watching machine that spawns actors to process each file's change event, using the file path as the actor's id. The processing actor involves some async work, including file io and network requests, that I'd like to cancel/abort when new change events come in for the same files. I haven't quite been able to figure out how to cleanly stop the previous actor that's still active before starting a new actor for the new events.
Here's a minimal repro of my best attempt so far: https://codesandbox.io/s/thirsty-easley-xx6mi8?file=/src/index.js
We can see from the console logs that the
update
event sent 1 second later results in the following warning:And after 3 seconds, the original update event will have been processed to completion, judging from the
params: { data: 1 }
event payload.Would really appreciate some ideas on how I can get this to work. Thanks!
P.S. any reason why there's no equivalent for the data arg for spawning machines with some initial context? I have a feeling the initialize event might be making things more difficult than they need to be for my use case.
Beta Was this translation helpful? Give feedback.
All reactions