Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Aug 21, 2024
1 parent bffe238 commit 766e263
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion crates/libs/metadata/src/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ impl TypeName {

pub const HResult: Self = Self("Windows.Foundation", "HResult");
pub const IAsyncAction: Self = Self("Windows.Foundation", "IAsyncAction");
pub const IAsyncInfo: Self = Self("Windows.Foundation", "IAsyncInfo");
pub const IAsyncActionWithProgress: Self =
Self("Windows.Foundation", "IAsyncActionWithProgress");
pub const IAsyncOperation: Self = Self("Windows.Foundation", "IAsyncOperation");
Expand Down
13 changes: 6 additions & 7 deletions crates/libs/windows/src/extensions/Foundation/Async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ pub trait Async: Interface {
fn get_results(&self) -> Result<Self::Output>;
}

// The `AsyncFuture` is needed to store some extra state needed to keep async execution up to date with possible changes to Rust execution context.
// Each async type implements `IntoFuture` rather than implementing `Future` directly so that this adapter may be used.
// The `AsyncFuture` is needed to store some extra state needed to keep async execution up to date with possible changes
// to Rust execution context. Each async type implements `IntoFuture` rather than implementing `Future` directly so that
// this adapter may be used.
pub struct AsyncFuture<A: Async> {
// Represents the async execution and provides the virtual methods for setting up a `Completed` handler and
// calling `GetResults` when execution is completed.
Expand All @@ -38,7 +39,7 @@ pub struct AsyncFuture<A: Async> {

// A shared waker is needed to keep the `Completed` handler updated.
// - `Option` is used to avoid allocations for async objects that have already completed.
// - `Arc` is used to share the `Waker` with the `Completed` handler and and potentially replace the `Waker`
// - `Arc` is used to share the `Waker` with the `Completed` handler and potentially replace the `Waker`
// since we don't have the ability to replace the `Completed` handler itself.
// - `Mutex` is used to synchronize replacing the `Waker` across threads.
waker: Option<Arc<Mutex<Waker>>>,
Expand All @@ -63,8 +64,6 @@ impl<A: Async> Future for AsyncFuture<A> {
type Output = Result<A::Output>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
println!("poll {cx:?}");

// A status of `Started` just means async execution is still in flight. Since WinRT async is always
// "hot start", if its not `Started` then its ready for us to call `GetResults` so we can skip all of
// the remaining set up.
Expand All @@ -74,8 +73,8 @@ impl<A: Async> Future for AsyncFuture<A> {

if let Some(shared_waker) = &self.waker {
// We have a shared waker which means we're either getting polled again or been transfered to
// another another execution context. Either way, we need to update the shared waker to make sure
// we've got the "current" waker.
// another execution context. As we can't tell the difference, we need to update the shared waker
// to make sure we've got the "current" waker.
let mut guard = shared_waker.lock().unwrap();
guard.clone_from(cx.waker());

Expand Down

0 comments on commit 766e263

Please sign in to comment.