Skip to content

async/await support #1701

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
Mar 31, 2021
Merged

async/await support #1701

merged 1 commit into from
Mar 31, 2021

Conversation

weissi
Copy link
Member

@weissi weissi commented Dec 9, 2020

Motivation:

The async/await proposal has entered the review phase, so we may want to
start looking into NIO with async/await.

Modifications:

  • Add EventLoopFuture.get() throws await
  • Add ChannelOutboundInvoker async methods

Result:

If async/await were actually implemented, you could use NIO together
with async/wait. So far, you can only compile your projects.

Copy link
Member

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Yup, looks right :-)

@weissi weissi changed the title [DO-NOT-MERGE] async/await support async/await support Mar 19, 2021
@weissi weissi marked this pull request as ready for review March 19, 2021 15:27
@weissi weissi requested a review from Lukasa March 19, 2021 15:27
@Lukasa Lukasa added the semver/none No version bump required. label Mar 19, 2021
@Lukasa
Copy link
Contributor

Lukasa commented Mar 19, 2021

As we are not committing to an API at this time I've flagged this as outside of semver.

Copy link

@kirilltitov kirilltitov left a comment

Choose a reason for hiding this comment

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

I think EventLoop should conform to @unchecked Sendable, but it's extremely tricky to do that with #if checks (not to mention that we don't have @unchecked attribute yet, and UnsafeSendable triggers an annoying compile warning). Same applies to EventLoopPromise (not sure about ELFs, didn't use them in async/await context yet)

@weissi weissi force-pushed the jw-asyncawait branch 5 times, most recently from 1df533d to 61fb58e Compare March 26, 2021 15:49
@weissi weissi requested a review from Lukasa March 26, 2021 15:50
@ktoso
Copy link
Member

ktoso commented Mar 29, 2021

I think EventLoop should conform to @unchecked Sendable, but it's extremely tricky to do that with #if checks (not to mention that we don't have @unchecked attribute yet, and UnsafeSendable triggers an annoying compile warning). Same applies to EventLoopPromise (not sure about ELFs, didn't use them in async/await context yet)

Yeah all those should be Sendable, though we don't yet have the unchecked implemented.

Note also that we won't be doing errors/warnings this year for the Sendable checks I believe...

@weissi weissi force-pushed the jw-asyncawait branch 2 times, most recently from 84ca4e5 to 8755460 Compare March 30, 2021 11:55
# - SANITIZER_ARG=--sanitize=thread # TSan broken still
- SWIFT_TEST_VERB=build # WARNING: Please remove (workaround https://bugs.swift.org/browse/SR-14268)
Copy link
Member Author

Choose a reason for hiding this comment

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

CC @Lukasa

Motivation:

The async/await proposal has entered the review phase, so we may want to
start looking into NIO with async/await.

Modifications:

- Add `EventLoopFuture.get() throws await`
- Add `ChannelOutboundInvoker` `async` methods

Result:

If async/await were actually implemented, you could use NIO together
with async/wait. So far, you can only compile your projects.
@weissi
Copy link
Member Author

weissi commented Mar 31, 2021

@Lukasa I pulled everything that isn't async/await out of this PR now (you know fixing main CI etc). So I think this is ready to go in once you're happy. It should be a non-functional change to the NIO module (or any other officially exported module).

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

:shipit:

@Lukasa Lukasa merged commit 75b52ab into apple:main Mar 31, 2021
hassila pushed a commit to hassila/swift-nio that referenced this pull request Apr 5, 2021
Motivation:

The async/await proposal has entered the review phase, so we may want to
start looking into NIO with async/await.

Modifications:

- Add `EventLoopFuture.get() throws await`
- Add `ChannelOutboundInvoker` `async` methods

Result:

If async/await were actually implemented, you could use NIO together
with async/wait. So far, you can only compile your projects.
hassila pushed a commit to hassila/swift-nio that referenced this pull request Apr 5, 2021
Motivation:

The async/await proposal has entered the review phase, so we may want to
start looking into NIO with async/await.

Modifications:

- Add `EventLoopFuture.get() throws await`
- Add `ChannelOutboundInvoker` `async` methods

Result:

If async/await were actually implemented, you could use NIO together
with async/wait. So far, you can only compile your projects.
hassila pushed a commit to hassila/swift-nio that referenced this pull request Apr 5, 2021
Motivation:

The async/await proposal has entered the review phase, so we may want to
start looking into NIO with async/await.

Modifications:

- Add `EventLoopFuture.get() throws await`
- Add `ChannelOutboundInvoker` `async` methods

Result:

If async/await were actually implemented, you could use NIO together
with async/wait. So far, you can only compile your projects.
// note: We have to define the variable `hasAsyncAwait` here because if we copy this code into the property below,
// it doesn't compile on Swift 5.0.
#if compiler(>=5.4)
#if compiler(>=5.4) // we cannot write this on one line with `&&` because Swift 5.0 doesn't like it...
Copy link

Choose a reason for hiding this comment

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

I just stumbled across this...I think you forgot to add the && $AsyncAwait here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@theMomax good spot! thank you, I'll fix this rn

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

I'm happy to help...thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/none No version bump required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants