Created
July 30, 2014 20:54
-
-
Save kjnilsson/437af18a1377bd5995df 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
type IdGenerator () = | |
let agent = MailboxProcessor<AsyncReplyChannel<int>>.Start(fun inbox -> | |
let rec loop c = async { | |
let! rc = inbox.Receive () | |
rc.Reply (c + 1) | |
return! loop (c + 1) } | |
loop 0) | |
member this.Next () = | |
agent.PostAndReply(fun rc -> rc) | |
let idGen = IdGenerator () | |
idGen.Next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment