sync send works
This commit is contained in:
+19
-13
@@ -1,35 +1,41 @@
|
||||
import { Machine, State, On, Do, Goto, Spawn, Unspawn } from '../index';
|
||||
import { Machine, State, On, Do, Goto, Spawn, Unspawn, interpret, Interpreter_T, send } from '../index';
|
||||
|
||||
const beginTimer = (ctx:C, e:E)=>{};
|
||||
const beginTimer = (ctx:C, e:E, self:Interpreter_T<S,E,C>)=>{ setTimeout(()=>{ send(self, ['timer-finished',null]); }, 800); };
|
||||
const log = (ctx:C, e:E, self:Interpreter_T<S,E,C>)=>{ console.log(self.state); };
|
||||
|
||||
type S = 'green' | 'yellow' | 'red';
|
||||
type E = ['entry',null] | ['timer-finished',null];
|
||||
type C = null;
|
||||
type C = {};
|
||||
|
||||
const machine =
|
||||
Machine<S,E,C>(
|
||||
State('green',
|
||||
On('entry',
|
||||
Do(beginTimer)
|
||||
On<S,E,C>('entry',
|
||||
Do(beginTimer),
|
||||
Do(log)
|
||||
),
|
||||
On('timer-finished',
|
||||
On<S,E,C>('timer-finished',
|
||||
Goto('yellow')
|
||||
)
|
||||
),
|
||||
State('yellow',
|
||||
On('entry',
|
||||
Do(beginTimer)
|
||||
On<S,E,C>('entry',
|
||||
Do(beginTimer),
|
||||
Do(log)
|
||||
),
|
||||
On('timer-finished',
|
||||
On<S,E,C>('timer-finished',
|
||||
Goto('red')
|
||||
)
|
||||
),
|
||||
State('red',
|
||||
On('entry',
|
||||
Do(beginTimer)
|
||||
On<S,E,C>('entry',
|
||||
Do(beginTimer),
|
||||
Do(log)
|
||||
),
|
||||
On('timer-finished',
|
||||
On<S,E,C>('timer-finished',
|
||||
Goto('green')
|
||||
)
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
const actor = interpret(machine, {context:{}});
|
||||
Reference in New Issue
Block a user