-
-
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
waitFor
fixes for cases when starting to waitFor
stopped interpreter
#3200
Conversation
|
@@ -429,12 +429,16 @@ export class Interpreter< | |||
this.listeners.add(listener); | |||
|
|||
// Send current state to listener | |||
if (this.status === InterpreterStatus.Running) { | |||
if (this.status !== InterpreterStatus.NotStarted) { |
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.
This is a small change in behavior. I was afraid to emit this at all times because this.initialState
might be impure
CodeSee Review Map:Review in an interactive map View more CodeSee Maps Legend |
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 a3d308b:
|
listener(this.state); | ||
} | ||
|
||
if (resolvedCompleteListener) { | ||
this.onDone(resolvedCompleteListener); | ||
if (this.status === InterpreterStatus.Stopped) { | ||
resolvedCompleteListener(); |
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.
can't call this within onDone
easily because there the callback expects to receive a doneInvoke
event. Here we know that it's a parameter-less observer.complete
though.
} | ||
}); | ||
|
||
const service = interpret(machine).start(); | ||
|
||
setInterval(() => service.send('NEXT'), 10); |
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.
This was resulting in a spammy logs coming from here:
xstate/packages/core/src/interpreter.ts
Lines 633 to 646 in a3d308b
if (this.status === InterpreterStatus.Stopped) { | |
// do nothing | |
if (!IS_PRODUCTION) { | |
warn( | |
false, | |
`Event "${_event.name}" was sent to stopped service "${ | |
this.machine.id | |
}". This service has already reached its final state, and will not transition.\nEvent: ${JSON.stringify( | |
_event.data | |
)}` | |
); | |
} | |
return this.state; | |
} |
as this interval was never disposed. So I've just changed this to a timeout that doesn't suffer from this problem.
setTimeout(() => { | ||
throw new Error('Should not reach here'); | ||
}, 50); |
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.
similarly, this was never disposed and could be thrown when other test was executing and thus fail that other test. I don't think this was adding that much here and by using await expect().rejects()
we make sure that this waitFor
throws
…ter (statelyai#3200) * Fixed `waitFor` hanging till timeout with final state matching the predicate * Fixed `waitFor` hanging till timeout with final state not matching the predicate * Fixed spammy sends in the waitFor test file
…tatelyai#3203) * Add missing changeset about changes in the core from statelyai#3200 * Update .changeset/red-walls-lay.md Co-authored-by: David Khourshid <davidkpiano@gmail.com> Co-authored-by: David Khourshid <davidkpiano@gmail.com>
No description provided.