Update windows-future with join and when functions
#3708
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I originally implemented support for the Windows
IAsyncXxxinterfaces in the windows-future crate to match how I had implemented it for C++/WinRT and while the async pattern must be implemented in exactly the same way to interop reliably, the language-specific helpers need not look exactly the same. The C++ version included a blockinggetmethod to wait for the results. This was based on C++'sstd::futurebut I realized that this is not very intuitive for Rust developers who might equate this more naturally with Rust'sJoinHandle. I might create a thread and wait for its result using the Standard Library as follows:This update renames the existing
getmethod tojoinso that it follows the same pattern:The
joinmethod works exactly the same and is implemented in the same way as before, although the implementation is now more streamlined to simplify maintenance.This update also adds the
whenmethod. While thewindows-futurecrate implements the Standard Library'sIntoFutureandFuturetraits, this isn't for everyone and you might just want a simple way to execute a closure when the future completes but without blocking the calling thread asjoindoes. Wiring this up is syntactically complicated for historical reasons:That's what
whenis for. It greatly simplifies this scenario: