Created
November 6, 2020 18:14
-
-
Save kdgerona/9a15e9a02a694875b7635e5103796dd0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// **** Traker **** | |
const context = { | |
worker_list: [], | |
task_queue: [], | |
enqueue: 0, | |
dequeue: 0, | |
} | |
const trackerConfig = { | |
id: 'tracker', | |
initial: 'tracking', | |
states: { | |
tracking: { | |
type: 'parallel', | |
initial: 'ticker', | |
states: { | |
ticker: { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
START_TICKER: 'interval' | |
} | |
}, | |
interval: { | |
invoke: { | |
src: () => { | |
return new Promise((resolve) => { | |
return setTimeout(() => resolve(), 1000) | |
}) | |
}, | |
onDone: 'checking' | |
} | |
}, | |
checking: { | |
on: { | |
"": [ | |
{ | |
target: 'interval', | |
cond: (context) => context.enqueue === context.dequeue | |
}, | |
{ | |
target: 'stop' | |
} | |
] | |
} | |
}, | |
stop: {}, | |
} | |
}, | |
timeout: {}, | |
balancing: {}, | |
}, | |
on: { | |
SEND_REQUEST: 'tracking.balancing' | |
} | |
}, | |
} | |
} | |
// **** Worker **** | |
// const workerConfig = { | |
// id: 'worker', | |
// initial: 'ready', | |
// states: { | |
// // initialization: { | |
// // // | |
// // }, | |
// ready: { | |
// entry: 'readyLog', | |
// on: { | |
// LOGIN_USER_REQUEST: { | |
// actions: 'processingLog', | |
// target: 'processing' | |
// } | |
// } | |
// }, | |
// processing: { | |
// initial: 'checkingUser', | |
// onDone: 'ready', | |
// states: { | |
// checkingUser: { | |
// after: { | |
// 3000: 'validating' | |
// }, | |
// actions: 'checkingUser' | |
// }, | |
// validating: { | |
// after: { | |
// 3000: 'done' | |
// }, | |
// actions: 'validating' | |
// }, | |
// done: { | |
// type: 'final' | |
// } | |
// } | |
// } | |
// } | |
// } | |
// const workerImplementations = { | |
// services: {}, | |
// actions: { | |
// readyLog: () => console.log('Worker is ready to recieve queries!'), | |
// processingLog: () => console.log('Currently processing request'), | |
// checkingUser: () => console.log('Checking User existence in the database'), | |
// validating: () => console.log('Validating user credentials') | |
// }, | |
// delays: {}, | |
// guards: {}, | |
// activities: {}, | |
// } | |
// *** Machine *** | |
const machine = Machine(trackerConfig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment