Skip to content
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

Overhaul async and future support #3213

Merged
merged 6 commits into from
Aug 22, 2024
Merged

Overhaul async and future support #3213

merged 6 commits into from
Aug 22, 2024

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Aug 21, 2024

This update does a few notable things to improve async and future support in the windows crate.

  • Async support in general is now provided by a crate extension rather than code generation. This approach was first introduced in Simplify how extension code for windows crate works #3110 and is a lot simpler to maintain as its all implemented in one place.

  • WinRT classes that represent async execution are now generated simply as type aliases for their respective async interfaces. This greatly simplifies their definitions and makes it a lot easier to understand what's going on. This does mean they lose their identity as runtime classes but in practice this is not very consequential as all of the things you'd want to do with that identity make little sense here. WinRT classes should never have been used to represent async execution. If such a case arises, we can always bring back some limited version.

  • The four async interfaces still provide a blocking get method but now also offer IntoFuture implementations that may be used in async functions or blocks. The resulting shared Future implementation supports multiple contexts and addresses the issue first reported in WinRT Futures should update their inner Waker #342. The implementation is somewhat inspired by WinRT Futures should update their inner Waker #342 and the execution test provided by Implement IntoFuture for WinRT async types #3177.

}

#[test]
fn switch_context() -> Result<()> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd love a simpler way to test switching execution contexts.

@kennykerr kennykerr requested a review from sivadeilra August 21, 2024 01:01
Comment on lines +15 to +18
// All four implementations are provided here and there is thus no need to implement this trait.
// This trait provides an abstraction over the relevant differences so that the `AsyncFuture`
// implementation below can be reused for all of them.
pub trait Async: Interface {

Choose a reason for hiding this comment

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

FWIW, you can use the sealed trait pattern to guarantee that there can be no external implementations of this trait. See https://rust-lang.github.io/api-guidelines/future-proofing.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the tip! There are some other spots where this might be useful.

@kennykerr kennykerr merged commit 0fb1a7f into master Aug 22, 2024
79 checks passed
@kennykerr kennykerr deleted the async branch August 22, 2024 12:44
This was referenced Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants