-
-
Save jasondown/11286701354cf53c9619e28d4281c452 to your computer and use it in GitHub Desktop.
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
[<AutoOpen>] | |
module Customer = | |
type internal CustomerMessage = | |
| Order | |
| Done | |
type HungryCustomer (vendingMachine : VendingMachine, id : int, output : Printer) = | |
let agent = MailboxProcessor<CustomerMessage>.Start(fun inbox -> | |
let rec orderLoop () = async { | |
let! msg = inbox.Receive() | |
match msg with | |
| Order -> | |
output.Print (sprintf $"Customer {id} is still hungry and orders another") | |
vendingMachine.BuyItem id | |
return! orderLoop () | |
| Done -> | |
output.Print (sprintf $"Customer {id} is getting full, so stops ordering") | |
return () | |
} | |
orderLoop() ) | |
member _.Order() = agent.Post Order | |
member _.Done() = agent.Post Done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment