Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type msg =
- | Fetch of AsyncReplyChannel<int>
- let counter =
- MailboxProcessor.Start(fun inbox ->
- let rec loop (lastRequestTime: DateTime) lastResult =
- async { let! msg = inbox.Receive()
- match msg with
- | Fetch(replyChannel) ->
- match DateTime.Now.Subtract(lastRequestTime).TotalSeconds < 5.0 with
- | true ->
- replyChannel.Reply(lastResult)
- return! loop lastRequestTime lastResult
- | false ->
- let newResult = lastResult + 1
- replyChannel.Reply(newResult)
- return! loop DateTime.Now newResult }
- loop (new DateTime(2015, 01, 01)) 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement