-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for F# async workflows #252
Comments
@ploeh Am currently on the road travelling, but will come back to this and the interesting qs raised in your blog post in a few days' time. |
Thank you @ploeh for your enthusiasm for Polly with F#! I have taken four main points from your blog post: You added around Polly: (a) extra exception-matching predicates to match (b) the curried helper-function to execute an async workflow through the Polly policy, translating between Tasks and F# async workflows (c) a function as (a) but extracting (d) a function to translate the thrown Taking these in a different order: (d) Polly has an in-built method (a) and (c) We now have several requests for better-handling of When that proposal is implemented, the in-built (b) / general F# support for Polly: Very happy for contributions! I love the functional style ( (Assuming (d) (a) and (c) as dealt with per above) ... (b-i) providing just your curried helper-function (b) out-of-box as part of the Polly package (or an extension package, eg (or something else?) If (b-i) is sufficient (or even just a good first step / adds enough value on its own), doing that sounds relatively straightforward and certainly useful. Particularly given it seems to provide an F# bridge for all Polly async executions, across all Policy types? (big win). If (b-ii), happy to discuss further! Depending on your thoughts to (b-i)/(b-ii) above, we can then think about how best to manage/package/support this. All input welcome from wider interested parties - I see that several people have 👍 this issue Thanks! |
I was mostly thinking about your item (b), since all the other features can easily be added in client code, if need be. The problem with a function like the following let private execute (policy : Policy) f req =
policy.ExecuteAsync(fun () -> f req |> Async.StartAsTask) |> Async.AwaitTask F# async workflows aren't This means that while it's possible to go back and forth between async workflows and the TPL, such transitions aren't free. There's synchronisation and (possibly) marshalling overhead every time one does that. The above It'd be nice to have a native Polly API that mirrors I haven't looked at the Polly code base, so I don't know how realistic this is. Furthermore, AFAIK, all the types involved in F# async workflows are defined in FSharp.Core, and I don't see how to add support for this without taking a dependency on that assembly. So it may not be desirable, but instead of reaching that conclusion all by myself, at least I thought I'd discuss it in public 😄 |
Thanks @ploeh. That was the answer I thought we would probably come to, based on your earlier comments, and my own reading around F# async workflows. However, likewise, I wanted to have your deeper F# experience speak to that rather than make an assumption 😄 For anyone interested in a port of Polly to F# in future - the implementations of each Polly policy type are defined quite clearly as higher-order functions - as "Funcs on a Func" - very much a functional mindset to Polly in that sense. Theory: The original definition of a sync Policy was (beautiful to my mind) an Practice: Those implementations can be clearly found in the classes named The rest of Polly is simpler concerns such as syntax/builder classes, supporting classes (eg the The exception to above statement that the entire definition of a Policy can be found in an Happy to provide further input/support to anybody wanting to port Polly, or just certain concepts, to F#. |
Triage of old issues: The core Polly team are not able to contribute this at present. Happy to provide guidance to anyone who may be looking to take this on as a project. As @ploeh says, to take full advantage of F# async workflows would essentially be a full rewrite of async Polly ("In order to make any difference, it'd need to use F# async workflows all the way."). |
Huge thanks again @ploeh for this useful exploration of Polly with F# (we've linked your blog post into the Polly readme) and for providing F# users with a means to bridge Polly nicely into F#, handling the I am going to close this out as outside of the scope the existing Polly team can deliver (on unfunded time). However, we continue to be happy to support and provide input/guidance to anyone wanting to take this on. Stepping right back and looking at the bigger picture: there is some impact in using the current Polly asynchronously in F#, due to the swapping back-and-forth between (On the smaller point of |
While you can make a Polly circuit breaker work with an F# async workflow, you have to jump through some hoops. Would it be possible to support F# async workflows out of the box?
I don't mind doing a bit of work myself, but I'd appreciate to hear from the Polly core team if this is something that they're interested in, and that they deem it possible.
The text was updated successfully, but these errors were encountered: