Skip to content

Instantly share code, notes, and snippets.

@7sharp9
Created December 6, 2011 00:25
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 7sharp9/1436079 to your computer and use it in GitHub Desktop.
Save 7sharp9/1436079 to your computer and use it in GitHub Desktop.
new pipelets loop
let computeAndRoute data routes = async{data |> transform |> router <| routes}
let mailbox = MailboxProcessor.Start(fun inbox ->
let rec loop routes = async {
let! msg = inbox.Receive()
match msg with
| Payload(data) ->
ss.Release() |> ignore
Async.StartWithContinuations(computeAndRoute data routes, ignore, errors, ignore)
return! loop routes
| Attach(stage) -> return! loop (stage::routes)
| Detach(stage) -> return! loop (List.filter (fun x -> x <> stage) routes)
}
loop [])
@panesofglass
Copy link

I prefer this one, personally. The other's use of RunSynchronously would seem to cause problems. Also, why are you passing ignore into the callback? Is the result expected to be unit?

@7sharp9
Copy link
Author

7sharp9 commented Dec 6, 2011

yep, the other functions are not needed in this instance, the other is the one Don recommended. Its from the MSDN documentation...

@panesofglass
Copy link

Did he mention why he recommended it? Is it better within the agent to behave in a more synchronous manner? What about deadlocks? I know those are possible when calling .Result on a Task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment