Skip to content

Instantly share code, notes, and snippets.

@davidgrenier
Created March 22, 2014 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidgrenier/9699865 to your computer and use it in GitHub Desktop.
Save davidgrenier/9699865 to your computer and use it in GitHub Desktop.
let cell init =
MailboxProcessor.Start(fun inbox ->
let rec loop n =
async {
let! result = inbox.Receive()
printfn "Received %d" result
return! loop result
}
loop init
)
let myCell = cell 4
myCell.Post 5
// Abstract the recursive call away.
let iterate init f =
MailboxProcessor.Start(fun inbox ->
let rec loop n =
async {
let! result = f inbox
return! loop result
}
loop init
)
let cell2 init =
iterate init (fun inbox ->
async {
let! result = inbox.Receive()
printfn "Received %d" result
return result
}
)
let myCell2 = cell2 8
myCell2.Post 32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment