javascript-state-machine icon indicating copy to clipboard operation
javascript-state-machine copied to clipboard

Conditional Transitions with asynchronous function

Open AdrianCuartas opened this issue 6 years ago • 1 comments

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.

AdrianCuartas avatar Apr 23 '18 11:04 AdrianCuartas

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

ulich avatar Mar 04 '19 14:03 ulich