Peer working

This commit is contained in:
Avraham Sakal
2023-05-17 18:09:44 -04:00
parent 636ba279c8
commit c0860a6b50
2 changed files with 68 additions and 14 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
import { Machine, State, On, SideEffect, Goto, Interpreter, Interpreter_T, send, Event_T, Context, SideEffectFunction_T, Peer, PeerCreationFunction_T, ContextMutationFunction_T } from '../index';
const wait = (ms:number)=>new Promise((resolve)=>{ setTimeout(()=>{ resolve(1); }, ms); });
const makeRequest : SideEffectFunction_T<Cc> = (ctx,e,self)=>{ send(self.peers.server, ['received-request',self]); };
const makeRequest : SideEffectFunction_T<Cc> = (ctx,e,self)=>{ send((self.peers.server as Interpreter_T<Cs>), ['received-request',self]); };
const sendResponse : SideEffectFunction_T<Cs> = (ctx,e,self)=>{ send(ctx.client, ['received-response',self]); };
const startTimer : SideEffectFunction_T<Cs> = async (ctx,e,self)=>{ await wait(1500); console.log(' timer actually finished'); send(self, ['timer-finished',null]); }
const log = (namespace:string)=>(ctx, e, self)=>{ console.log(namespace, self.state, e[0]); };