Skip to content

Conversation

Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Dec 12, 2022

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.

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.
@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Dec 12, 2022
/// - 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")
Copy link
Member

@dnadoba dnadoba Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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.

Copy link
Contributor Author

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.

@Lukasa Lukasa requested a review from dnadoba December 12, 2022 13:29
Copy link
Member

@dnadoba dnadoba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Lukasa Lukasa enabled auto-merge (squash) December 12, 2022 13:33
@Lukasa Lukasa merged commit a58500a into apple:main Dec 12, 2022
@ktoso
Copy link
Member

ktoso commented Dec 12, 2022

LGTM :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants