jakesgordon / javascript-state-machine

A javascript finite state machine library
MIT License
8.69k stars 964 forks source link

Conditional Transitions with asynchronous function #156

Open AdrianCuartas opened 6 years ago

AdrianCuartas commented 6 years ago

Is it possible? I tried in a different ways but I always get an error.

I need to do something like this: states: A, B and C. transition: step.
From state A, 'step' transition must be a function which returns B or C depending on asynchronous operation.

var fsm = new StateMachine({
    init: 'A',
    transitions: [
      { name: 'step', 
        from: 'A', 
        to: async function() { 
              var state = await getState()      
              return state
         }
     }
    ]
  });

Thanks in advance.

ulich commented 5 years ago

I could try to file a PR for this. Any concerns @jakesgordon ?