Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.81 KB | None | 0 0
  1. type msg =
  2.     | Fetch of AsyncReplyChannel<int>
  3.  
  4. let counter =
  5.     MailboxProcessor.Start(fun inbox ->
  6.         let rec loop (lastRequestTime: DateTime) lastResult =
  7.             async { let! msg = inbox.Receive()
  8.                     match msg with
  9.                     | Fetch(replyChannel) ->
  10.                         match DateTime.Now.Subtract(lastRequestTime).TotalSeconds < 5.0 with
  11.                         | true ->
  12.                             replyChannel.Reply(lastResult)
  13.                             return! loop lastRequestTime lastResult
  14.                         | false ->
  15.                             let newResult = lastResult + 1
  16.                             replyChannel.Reply(newResult)
  17.                             return! loop DateTime.Now newResult }
  18.         loop (new DateTime(2015, 01, 01)) 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement