use eventQueue; process Reactions in proper order
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Machine, State, On, Do, Goto, Spawn, Unspawn, interpret, Interpreter_T, send, Event_T } from '../index';
|
||||
import { Machine, State, On, SideEffect, Goto, Spawn, Unspawn, interpret, Interpreter_T, send, Event_T } from '../index';
|
||||
|
||||
const beginTimer = (ctx:C, e:Event_T, self:Interpreter_T)=>{ setTimeout(()=>{ send(self, ['timer-finished',null]); }, 800); };
|
||||
const log = (ctx:C, e:Event_T, self:Interpreter_T)=>{ console.log(self.state); };
|
||||
@@ -16,8 +16,8 @@ const machine =
|
||||
Machine(
|
||||
State('green',
|
||||
On('entry',
|
||||
Do(beginTimer),
|
||||
Do(log)
|
||||
SideEffect(beginTimer),
|
||||
SideEffect(log)
|
||||
),
|
||||
On('timer-finished',
|
||||
Goto('yellow')
|
||||
@@ -25,8 +25,8 @@ const machine =
|
||||
),
|
||||
State('yellow',
|
||||
On('entry',
|
||||
Do(beginTimer),
|
||||
Do(log)
|
||||
SideEffect(beginTimer),
|
||||
SideEffect(log)
|
||||
),
|
||||
On('timer-finished',
|
||||
Goto('red')
|
||||
@@ -34,8 +34,8 @@ const machine =
|
||||
),
|
||||
State('red',
|
||||
On('entry',
|
||||
Do(beginTimer),
|
||||
Do(log)
|
||||
SideEffect(beginTimer),
|
||||
SideEffect(log)
|
||||
),
|
||||
On('timer-finished',
|
||||
Goto('green')
|
||||
|
||||
+12
-13
@@ -1,4 +1,4 @@
|
||||
import { Machine, State, On, Do, Goto, Spawn, Unspawn, interpret, Interpreter_T, send, Event_T } from '../index';
|
||||
import { Machine, State, On, SideEffect, Goto, Spawn, Unspawn, interpret, Interpreter_T, send, Event_T } from '../index';
|
||||
|
||||
const wait = (ms:number)=>new Promise((resolve)=>{ setTimeout(()=>{ resolve(1); }, ms); });
|
||||
const makeRequest = (ctx,e,self)=>{ send(ctx.serverActor, ['received-request',self]); };
|
||||
@@ -21,27 +21,26 @@ const client =
|
||||
Machine(
|
||||
State('idle',
|
||||
On('entry',
|
||||
Do(log),
|
||||
SideEffect(log),
|
||||
),
|
||||
On('server-created',
|
||||
|
||||
Do((_ctx,[_eventName,serverActor],self)=>{ self.context.serverActor=serverActor; }),
|
||||
SideEffect((_ctx,[_eventName,serverActor],self)=>{ self.context.serverActor=serverActor; }),
|
||||
Goto('making-request')
|
||||
)
|
||||
),
|
||||
State('making-request',
|
||||
On('entry',
|
||||
Do(log),
|
||||
Do(makeRequest),
|
||||
SideEffect(log),
|
||||
SideEffect(makeRequest),
|
||||
Goto('awaiting-response')
|
||||
),
|
||||
),
|
||||
State('awaiting-response',
|
||||
On('entry',
|
||||
Do(log),
|
||||
SideEffect(log),
|
||||
),
|
||||
On('received-response',
|
||||
Do(log),
|
||||
SideEffect(log),
|
||||
Goto('making-request')
|
||||
),
|
||||
),
|
||||
@@ -60,20 +59,20 @@ const server =
|
||||
Machine(
|
||||
State('awaiting-request',
|
||||
On('entry',
|
||||
Do(log),
|
||||
SideEffect(log),
|
||||
),
|
||||
On('received-request',
|
||||
Do((_ctx,[_eventName,clientActor],self)=>{ self.context.clientActor=clientActor; }),
|
||||
SideEffect((_ctx,[_eventName,clientActor],self)=>{ self.context.clientActor=clientActor; }),
|
||||
Goto('sending-response')
|
||||
),
|
||||
),
|
||||
State('sending-response',
|
||||
On('entry',
|
||||
Do(log),
|
||||
Do(startTimer)
|
||||
SideEffect(log),
|
||||
SideEffect(startTimer)
|
||||
),
|
||||
On('timer-finished',
|
||||
Do(sendResponse),
|
||||
SideEffect(sendResponse),
|
||||
Goto('awaiting-request')
|
||||
)
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user