Skip to content

Instantly share code, notes, and snippets.

@digitalBush
Created January 7, 2014 19:48
Show Gist options
  • Save digitalBush/8305621 to your computer and use it in GitHub Desktop.
Save digitalBush/8305621 to your computer and use it in GitHub Desktop.
Port of Bryan Hunter's (@bryan_hunter) Cheap Process Erlang demo to F# (https://github.com/bryanhunter/IntroToErlangTalk/blob/nashjug-2013/cheap_process/cheap_process.erl)
module CheapProcess =
open System.Diagnostics
type Agent<'T> = MailboxProcessor<'T>
type Answer =
Ok
let rec start howMany (pid: Agent<Answer>) =
Agent.Start(fun inbox ->
async {
match howMany with
| 0 ->
pid.Post(Ok)
return ()
| _ ->
let child = start (howMany-1) pid
child.Post(Ok)
let! msg = inbox.Receive()
match msg with
| Ok -> return ()
})
let startAndTime howMany =
Agent.Start(fun inbox ->
async {
let clock = Stopwatch.StartNew()
let child=start howMany inbox
let! msg=inbox.Receive()
printfn "%O" clock.Elapsed
return ()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment