-
Notifications
You must be signed in to change notification settings - Fork 698
Make EventLoopFuture.wait() unavailable from async #2331
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
Conversation
Motivation: ELF.wait() waits for a condition variable to become true, which can frequently lead to extremely long waits. This is a bad thing to call on a Swift Concurrency thread, especially as we have ELF.get() which is preferable. Modifications: Make ELF.wait() unavailable from async. Result: Users are encouraged to use the correct primitive.
/// - returns: The value of the `EventLoopFuture` when it completes. | ||
/// - throws: The error value of the `EventLoopFuture` if it errors. | ||
@available(*, noasync, message: "threads can change between suspension points and therefore the thread specific value too") |
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.
@available(*, noasync, message: "threads can change between suspension points and therefore the thread specific value too") | |
@available(*, noasync, message: "threads can change between suspension points and therefore the thread specific value too", renamed: "get()") |
This will produce a fixit that will allow users to easily replace it with .get()
warning: instance method 'wait' is unavailable from asynchronous contexts; threads can change between suspension points and therefore the thread specific value too; this is an error in Swift 6
try future.wait()
^~~~
get
Users still need to add await
infront but the compiler will nicely provide a fixit for that too.
error: expression is 'async' but is not marked with 'await'
try future.get()
^~~~~~~~~~~~~~~~
await
I understand that we want to encourage users to use get()
but I'm not sure I quite understand the message
:
threads can change between suspension points and therefore the thread specific value too
wait()
doesn't use any thread specific value and AFAIK it is "safe" to use in an async context (except deadlocks) but is just not performant.
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.
Yeah that is just an overhang from a previous usage I didn't replace.
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.
LGTM!
LGTM :) |
Motivation:
ELF.wait() waits for a condition variable to become true, which can frequently lead to extremely long waits. This is a bad thing to call on a Swift Concurrency thread, especially as we have ELF.get() which is preferable.
Modifications:
Make ELF.wait() unavailable from async.
Result:
Users are encouraged to use the correct primitive.