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

Add async ready support #3221

Merged
merged 6 commits into from
Aug 27, 2024
Merged

Add async ready support #3221

merged 6 commits into from
Aug 27, 2024

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Aug 26, 2024

Building on #3213, this update adds support for creating async implementations that are immediately ready with a value. This is analogous to https://doc.rust-lang.org/stable/std/future/fn.ready.html and an acknowledgement that there's no need to spin up a thread or switch contexts if the results are already available - its way more efficient to just return them directly.

For example, let's say you need an IAsyncOperation<i32> that results in a value of 123. You can create one as follows:

use windows::{core::*, Foundation::*};

fn main() -> Result<()> {
    let ready = IAsyncOperation::ready(Ok(123));

    assert_eq!(ready.get()?, 123);

    Ok(())
}

The get call, which blocks the calling thread until the results are available, will return immediately with the expected value.

@kennykerr

This comment was marked as resolved.

@kennykerr kennykerr merged commit 0cce46b into master Aug 27, 2024
79 checks passed
@kennykerr kennykerr deleted the async-ready branch August 27, 2024 00:52
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.

1 participant