-
Notifications
You must be signed in to change notification settings - Fork 648
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
_NIOConcurrency: Rename completeWithAsync(_:) to completeWithTask(_:) and return task #1911
Conversation
//cc @glbrntt |
Signed-off-by: Si Beaumont <beaumont@apple.com>
508011b
to
8b78232
Compare
Soundness should be fixed by #1913 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me.
If you mean "leaks implementation detail" then kind of yeah, but it does not cause a "leak leak". Let's think if this leaking of impl detail is actually "impl detail" or "necessary detail"... There's basically two ways to cancel a task:
In that sense... Since this API is intended to be called from a "probably not async context" (maybe it is a sync function but actually running inside of a Task, but in any case we potentially cannot Perhaps a different name here would be better though? The alternative, without offering such API, is to force people to: |
I'm with @ktoso: while it absolutely leaks an implementation detail, this is a detail that is unavoidably necessary for participating correctly in structured concurrency. |
I would be open to renaming to |
And concretely the reason this change was proposed was for the grpc-swift project, which will want something like this. The fact that they need it suggests that it's likely to be generally useful. |
…pleteWithTask(_:) Signed-off-by: Si Beaumont <beaumont@apple.com>
Ah... I see I broke the |
The underscore module is not API stable, but the api breakage script doesn’t know that. We can merge over it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and "yay!" for the rename while at it :)
Return
Task
fromEventLoopPromise.completeWithAsync(_:)
wrapper.Motivation:
Bridging an
async
function into NIO is done by callingcompleteWithAsync(_ body:)
on anEventLoopPromise
. This spins up aTask
andawait
s the result of theasync
closure that was passed in and uses the result to fulfil the promise with the value of the function, if it was successful, or with the error, if the function threw.In some cases we may want to cancel this operation from the outside.
Modifications:
This patch adds a discardable return value to
EventLoopPromise.completeWithAsync(_:)
which is theTask
it creates.Result:
Users of
EventLoopPromise.completeWithAsync(_:)
are now able to explicitly cancel theTask
that is being used to fulfil the promise.