Skip to content

Instantly share code, notes, and snippets.

@kjnilsson
Created July 30, 2014 20:54
Show Gist options
  • Save kjnilsson/437af18a1377bd5995df to your computer and use it in GitHub Desktop.
Save kjnilsson/437af18a1377bd5995df to your computer and use it in GitHub Desktop.
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