Files
fsm/src/tests/00-basic.ts
T
2023-05-11 23:26:38 -04:00

35 lines
655 B
TypeScript

import { Machine, State, On, Do, Goto, Spawn, Unspawn } from '../index';
const beginTimer = (ctx:C, e:E)=>{};
type S = 'green' | 'yellow' | 'red';
type E = ['entry',null] | ['timer-finished',null];
type C = null;
const machine =
Machine<S,E,C>(
State('green',
On('entry',
Do(beginTimer)
),
On('timer-finished',
Goto('yellow')
)
),
State('yellow',
On('entry',
Do(beginTimer)
),
On('timer-finished',
Goto('red')
)
),
State('red',
On('entry',
Do(beginTimer)
),
On('timer-finished',
Goto('green')
)
),
);