-
Notifications
You must be signed in to change notification settings - Fork 106
Forbid await
in finally blocks
#51
Comments
how is that different than |
@getify it's not. However we can't fix |
I don't really understand this. There's many use cases where I want to do async things inside a finally block. So many in fact that C# is introducing a whole new type devoted to this. dotnet/roslyn#114 |
I'm not sure that allowing await within finally blocks necessarily means that the operation is not cancelable. The cancelation routine might even require calling out other async functions. |
+1 @zenparsing, pretty much what I was going to write. It does imply that any cancelable promise type might want to change its onCanceled from returning void to returning a promise. |
@domenic C# has a proposal for a new type for this. For what it's worth his proposal isn't the most correct. I recall talking to Eric Lippert about this let me see if I can dig this. The mega-thread you posted on the es-observable issues shows that there is a lot to learn though. In C#, cancellation works differently anyway. I'll investigate further. Disallowing I talked to @petkaantonov about what bluebird does in coroutines and to @bwoebi about what PHP does in task aborts. Also bringing @rdlowrey for having implemented coroutines with these semantics. @zenparsing - what bluebird does is allow I think that as future compatibility with cancellation semantics is a goal - we need to figure out some solution to this problem. When we had these discussions implementing |
I can only see the downsides of forbidding this, and no upsides.
The promise is still cancelled, but the underlying finally block continues to run. What is the issue with that? |
There is a difference with generators in terms of the return result. The return result of an async function is a promise. Canceling the promise changes its behavior directly. But Generators are different. |
@spion so the promise is marked as cancelled but the async function can continue running for as long as it wants (even forever) and does not have to actually attempt cleanup and finish? |
@benjamingr if you want to support async cleanup, yes. I don't see an issue with its continued work in the background - as long as it doesn't observably affect the resulting promise. |
Hmm, then that guarantee (or lack of) will need to be documented in cancellable promises. That sounds reasonable to me. |
@domenic Should a hypothetical |
@petkaantonov ^ this makes sense to me. (Where |
I think we can allow |
If finally blocks are going to be used for clean up when async functions will be cancellable and await is allowed in
finally
then it looks like there is no way to perform actual cancellation in async functions.See tc39/proposal-observable#33 (comment) for a convincing and well thought out argument by @jhusain for generators and cleanup.
The text was updated successfully, but these errors were encountered: