Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type CounterMessage =
- | Update of float
- | Reset
- let counter = MailboxProcessor.Start(fun agent ->
- let rec loop sum count = async {
- let! msg = agent.Receive()
- match msg with
- | Reset -> return! loop 0.0 0.0
- | Update value ->
- let sum, count = sum + value, count + 1.0
- printfn "Average: %f" (sum / count)
- do! Async.Sleep(1000)
- return! loop sum count
- }
- loop 0.0 0.0)
- couter.Post(Update, 10.0)
- couter.Post(Reset)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement