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

State Machine Timeout #29

Open
stefnotch opened this issue Mar 10, 2019 · 0 comments
Open

State Machine Timeout #29

stefnotch opened this issue Mar 10, 2019 · 0 comments

Comments

@stefnotch
Copy link
Contributor

Timeouts are reasonably common in state machines, however manually implementing them requires quite a number of lines of code. It might be nice if this library had built-in support for them.

Maybe something along the lines of:

public stateTimeout<U extends keyof T>(state: U, to: keyof T, timeout: number) {
         this.on(state, (from, context) => {
            (<any>context).timeout = setTimeout(() => {
              this.go(to);
            }, timeout);
          });
        
          this.onExit(state, (from, context) => {
            if ((<any>context).timeout) {
              clearTimeout((<any>context).timeout);
              (<any>context).timeout = 0;
            }
            return true;
          });
      }
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

No branches or pull requests

1 participant