Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure spawned actors are present in state.children. Fixes #795 #1553

Merged
merged 5 commits into from
Oct 19, 2020

Conversation

davidkpiano
Copy link
Member

This PR ensures that all actors (spawned/invoked) are represented in state.children.

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2020

🦋 Changeset detected

Latest commit: c0309a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
xstate Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -844,17 +849,14 @@ export class Interpreter<
: serviceCreator;

if (isPromiseLike(source)) {
this.state.children[id] = this.spawnPromise(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: so those were setting the child on the not-yet-updated this.state?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember the specifics, but these did appear on the updated this.state

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so I've jumped into the code to understand this a little bit better and this is what I've learns - spawn is not handled by this part of the code at all, this is processing of start actions (so basically for starting invokes / activities) and that's why this has not been working. This is IMHO a very strong candidate for the refactor in v5 because invoke/spawn should IMHO behave in the very same way. The only difference should be that invokes are static and bound to state whereas spawned actors are dynamic.

However, right now they differ because invokes are more lazy and spawns are eager. For example if an invoke gets "immediately" cancelled within a single macrotask then it is not even started (according to the SCXML spec statesToInvoke are only processed after the internalQueue gets empty), but spawn does not behave in this way as it's eager (handled right away, rather than deferred to the end of the current macrotask).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but spawn does not behave in this way as it's eager (handled right away, rather than deferred to the end of the current macrotask).

This behavior is fixed in the next branch already. Spawned actors will behave exactly the same way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great to hear 🚀

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@davidkpiano davidkpiano merged commit 04fe692 into master Oct 19, 2020
@davidkpiano davidkpiano deleted the davidkpiano/795 branch October 19, 2020 03:02
This was referenced Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants