-
Notifications
You must be signed in to change notification settings - Fork 21
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
finally! #651
Comments
Note that there is a question for async/asyncSeq about whether such operations would be performed if the operation is cancelled, and how that would be implemented. |
I can see two possible ways to handle cancellation in
asyncSeq {
try
...
finally!
let token = getCancellationTokenForThisBlock()
if token.IsCancellationRequested then
doVitalCleanup()
else
yield! longRunningAsyncProcess()
yield UpdateItemsComplete
doVitalCleanup()
} Note that I did not list " And BTW, I like the issue title. 😄 |
Why does it need |
Why not Edit: |
There is no currently easy way to say "Await async whatever, and then log this message".
Clearly it's a problem. I think |
Can't compiler just look into |
The more general problem is already that if you do a lot of code inside a computation expression (like async), you lose the interactive-driven-development as you cannot easily send a part of computation expression code to FSI. |
This seems to be required to implement native support for IAsyncDisposable |
IAsyncDisposable sounds kind of funny: |
Same idea, but sometimes you need to call async methods during the cleanup |
I think and want this feature. First version (simplicity but will be hard blocked): Final result: They couldn't write it average level engineer... |
@dsyme The possible hack was to either change CancellationToken in AsyncActivation.aux.Token for cconts or to add a boolean value to AsyncActivation indicating that we are now in "forced" ccont state. So the problem is: how to deal with cancellation in this case? On the other hand computation is cancelled and it's somewhat logical to cancel all async computations, finally included. On the other hand it makes sense to force finally computations because user could take some kind of distributed lock in async operation and it needs to be freed and so on. |
ping @dsyme I've skimmed through the issue again and you've raised this exact topic in 2018. Funny how I just missed it. Can you please share your thoughts on how should we deal with cancellation in general? And I guess hacks mentioned above are not the really desired ones am I right? |
I've marked this approved-in-principle - I don't know why it wasn't approved
@En3Tho My apologies for not replying to the above. It would be great to get a PR together and discuss this in context |
I propose we add
try .. finally! ...
to allowfinally
actions to be monadic.The current computation-expression desugaring of
try .. finally ...
allows only aunit -> unit
action in the compensation branch.. However there are cases where an asynchronous or other monadic imperative action makes sense in exception compensation, e.g. using AsyncSeq:The current way of doing this in F# is some mess like this:
The same effect can also currently be achieved with a custom operation, something like this, but just supporting
finally!
looks more sensible:Pros and Cons
The advantages of making this adjustment to F# are orthogonality/simplicity.
The disadvantages of making this adjustment to F# are cost.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related Items
The text was updated successfully, but these errors were encountered: