Skip to content

Mark Task.wait() noasync and provide Task.get() #668

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

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

Lukasa
Copy link
Collaborator

@Lukasa Lukasa commented Feb 13, 2023

Motivation

Task.wait() is a convenience method to avoid needing to wait for the response future. This has had the effect of "laundering" a noasync warning from EventLoopFuture.wait(), hiding it within a purely sync call that may itself be used in an async context.

We should discourage using these and prefer using .get() instead.

Modifications

Mark Task.wait() noasync.
Add Task.get() for backward compatibility.

Result

Safer migration to Swift concurrency

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Feb 13, 2023
@dnadoba
Copy link
Collaborator

dnadoba commented Feb 13, 2023

You need to generate linux tests, otherwise LGTM.

@dnadoba dnadoba enabled auto-merge (squash) February 13, 2023 17:56
/// - throws: The error value of the `EventLoopFuture` if it errors.
/// - returns: The value of ``futureResult`` when it completes.
/// - throws: The error value of ``futureResult`` if it errors.
@available(*, noasync, message: "wait() can block indefinitely, prefer get()", renamed: "get()")
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to just #if around the available attribute and avoid the duplicate impl, if you wanted to

Copy link
Collaborator

Choose a reason for hiding this comment

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

Motivation

Task.wait() is a convenience method to avoid needing to wait for the
response future. This has had the effect of "laundering" a noasync
warning from EventLoopFuture.wait(), hiding it within a purely sync call
that may itself be used in an async context.

We should discourage using these and prefer using .get() instead.

Modifications

Mark Task.wait() noasync.
Add Task.get() for backward compatibility.

Result

Safer migration to Swift concurrency
@Lukasa Lukasa force-pushed the cb-deprecate-task-wait branch from 8113707 to 7501e6b Compare February 14, 2023 09:44
@dnadoba dnadoba merged commit 864c8d9 into swift-server:main Feb 14, 2023
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