Skip to content

Commit

Permalink
feat(emitter): flush remaining effects queue on state update
Browse files Browse the repository at this point in the history
Previously, if a state update arrived while an effects queue was in the middle of being processed,
the active effects queue was simply discarded and the new one processed. This was potentially buggy
in that `onEnd` callbacks might not be called even if the `onStart` was (and similar clean-up bugs
if relying on a separate effect or `effects:end` to run clean-up, stop animations etc.). Now, any
outstanding effects are flushed when a new state update arrives, ensuring those callbacks will all
immediately be called before the new queue is started.

BREAKING CHANGE: This may be a breaking change if you were relying on the previous queue being
discarded. Given that would be highly timing dependent between when moves where executed, that seems
unlikely to be the case, but flagging this as potentially breaking nonetheless.

Closes #57
  • Loading branch information
delucis committed Jan 22, 2022
1 parent 9cee298 commit f4076aa
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/emitter/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class EffectsEmitterImpl<S extends ClientState> implements EffectsEmitter<S> {
* Update the queue state when a new state update is received from boardgame.io.
*/
public onUpdate(state: null | S): void {
this.flush();
const prevState = this.latestState;
this.latestState = state;
if (
Expand Down

0 comments on commit f4076aa

Please sign in to comment.