-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Drop support for handling promises returned by fromCallback
#3282
Conversation
🦋 Changeset detectedLatest commit: d6311a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d6311a2:
|
CodeSee Review Map:Review in an interactive map View more CodeSee Maps Legend |
Alternatively we could allow promises but ignore the completion value. In such a case though - what to do about errors? We probably should handle them but then out handling wouldnt be symmetric (and thus somewhat weird) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of this; can you re-merge the v5/improved-spawn-1
PR as there are new changes?
@davidkpiano ye, gonna handle the merge tomorrow @mattpocock would love your input on this one too |
0c89c96
to
98a7202
Compare
fc6e932
to
d6311a2
Compare
invokeCallback
fromCallback
This was already approved before but it got stale and I just rebased it. @davidkpiano could you take a second look at this? |
My main rationale for this is that it's an easy mistake to do this:
The problem with this code is that this promise implicitly completes very quickly and thus the parent stops accepting events sent out from this callback. Here the
async
was used as a convenient mechanism to useawait
, the intention wasn't really to complete this callback actor withundefined
. Note that this is not a made-up example - this has been reported a while back on Discord by Kent and the resulting situation was quite hard to debug for a user because XState was logging cryptic errors in this case.This can easily be refactored to:
Note that supporting promises (what is being removed from here) doesn't also play that well with current types as the return value of
fromCallback
isBehavior<TEvent, undefined>
whereas thatundefined
is not a strong guarantee with a returned promise.