Skip to content

Instantly share code, notes, and snippets.

@jasondown
Last active January 14, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasondown/6a1a190ea5621a67f6b956a58a416c0d to your computer and use it in GitHub Desktop.
Save jasondown/6a1a190ea5621a67f6b956a58a416c0d to your computer and use it in GitHub Desktop.
// Run simulation
let cts = new System.Threading.CancellationTokenSource()
Async.Start(startOrdering cust1 3, cts.Token) // order every 3 seconds
Async.Start(startOrdering cust2 5, cts.Token) // order every 5 seconds
Async.Start(startOrdering cust3 1, cts.Token) // order every second nom nom
// Call either of these at random times to see there is no blocking
// during the simulation or to see how the restocking message causes
// different behaviour depending on the current state of the vending
// machine and its queued messages
vm.Restock(10)
showCurrentStock()
// If needed, stop the entire simulation
cts.Cancel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment