export interface ControlState { controlState : string ; } /**
 * A state-action machine next function that returns the next action thunk
 * based on the passed in state.
 */ export type Next < S > = ( state : S ) => ( ( ) => Promise < unknown > ) | null ; /**
 * A state-action machine model that given the current state and an action
 * response returns the state for the next step.
 */ export type Model < S > = ( state : S , res : any ) => S ; param initialState param next param model param onStepComplete export async function stateActionMachine < S extends ControlState > ( initialState , next , model ) { let state = initialState ; let nextAction = next ( state ) ; while ( nextAction != null ) { const actionResponse = await nextAction ( ) ; const newState = model ( state , actionResponse ) ; state = newState ; nextAction = next ( state ) ; } return state ; }