-
Notifications
You must be signed in to change notification settings - Fork 507
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
Conversation
} | ||
|
||
#[test] | ||
fn switch_context() -> Result<()> { |
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.
I'd love a simpler way to test switching execution contexts.
// 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 { |
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.
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
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.
Thanks for the tip! There are some other spots where this might be useful.
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 offerIntoFuture
implementations that may be used inasync
functions or blocks. The resulting sharedFuture
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 ImplementIntoFuture
for WinRT async types #3177.