Comments (7)
Looks like the implementation of the TryWith
, TryFinally
and other build upon those functions are flawed.
If you look at the implementation of TryFinally
(code):
member this.TryFinally(body, compensation) =
try this.ReturnFrom(body())
finally compensation()
Lets replace the call to ReturnFrom
with it's body, and add a type on the body
parameters
member this.TryFinally(body: unit -> AsyncResult<_>, compensation) =
try body()
finally compensation()
Can you spot the problem?
The body
function is returning an Async
, it might not have completed yet. However the control flow in the TryFinally
function already goes on, and as the execution of the body
function already ended, the finally
block is executed with the compensation
function.
If you compare the internals of this Builder
with the internals of the AsyncBuilder
from the FSharp.Core you can see, that there the try-finally and try-with constructs are lifted into the Async
world. In this version of the builder the constructs are left outside, that's why you have the difference in the behaviour.
from domainmodelingmadefunctional.
Think it makes sense, thanks.
from domainmodelingmadefunctional.
@mexx I changed the 2 methods like this:
member this.TryWith(body, handler) = async {
try
let! b = body()
return this.ReturnFrom(b)
with e ->
return handler e }
member this.TryFinally(body, compensation) = async {
try
let! b = body()
return this.ReturnFrom(b)
finally
compensation() }
The dispose works as expected now, but I'm not sure if it's really as simple as this, because the AsyncBuilder
implementation of these is a lot more involved (perhaps because of doing optimizations?).
from domainmodelingmadefunctional.
@kerams I'm not certain that the calls to this.ReturnFrom
are even necessary.
It's that simple, the AsyncBuilder
implementation can't use any syntax sugar, like you do now with the async
.
from domainmodelingmadefunctional.
Alright, thanks a lot!
from domainmodelingmadefunctional.
Just curious... Is this one fixed by #10?
from domainmodelingmadefunctional.
(Finally revisiting all these issues!)
I think this is fixed now. Closing
from domainmodelingmadefunctional.
Related Issues (14)
- Where is the code? HOT 1
- fail to build on ubuntu HOT 2
- Fails to build because module OrderTaking.PlaceOrder.Implementation is internal HOT 3
- Question: Is there a complete implementation including persistence and serialization? HOT 2
- Question: is it still the recommended way to do dependency parameterization? HOT 2
- Domain Modelling Made Functional Book HOT 3
- How to read CheckedAddress from a data store
- Noticed Differences, so just want to clarify the things
- An compilling exemplo in .net 6
- asyncResult not working HOT 3
- Porting to .NET Core/Standard HOT 11
- AsyncResult.catch don't work as expected HOT 4
- How to interact with presistent? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from domainmodelingmadefunctional.