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

Fix bug where setTimeout lingered on abort and a nested state machine was running #57

Merged
merged 7 commits into from
Aug 29, 2023

Conversation

nibble-4bits
Copy link
Owner

Take the following example:

const machineDefinition = {
  StartAt: "FirstState",
  States: {
    FirstState: {
      Type: "Parallel",
      Branches: [
        {
          StartAt: "Wait",
          States: {
            Wait: { Type: "Wait", Seconds: 60, End: true },
          },
        },
      ],
      End: true,
    },
  },
};

const stateMachine = new StateMachine(machineDefinition);
const { abort } = stateMachine.run(input);

abort();

When calling abort() after starting the execution, the execution is aborted, however, the script doesn't completely finish as the sleep call from the inner Wait state isn't canceled. In this example, that means the setTimeout in sleep won't resolve until the 60 seconds specified in Seconds have elapsed.

This PR fixes that behavior.

@nibble-4bits nibble-4bits merged commit d430092 into develop Aug 29, 2023
1 check passed
@nibble-4bits nibble-4bits deleted the fix/abort-sleep-nested-state-machine branch August 29, 2023 01:30
This was referenced Sep 4, 2023
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.

1 participant