Request
A helper that returns an IAsyncOperation<T> or IAsyncAction already in the Completed state, carrying a fixed result, with no coroutine frame. co_await make_ready(x), .get(), and a Completed handler all complete synchronously.
Why
Returning an already-known value from an async-typed API today spins up a coroutine frame and its promise/allocation just to hand back a value that's already in hand. A ready-made completed object skips the frame entirely — the common "the answer is cached / trivially available" path.
Where
wil/cppwinrt.h. This was prototyped in microsoft/cppwinrt#1608 and then pulled back out: cppwinrt should stay a pure projection, and the coroutine/async helpers belong in WIL (sylveon on #1608).
Implementation
Prototype: microsoft/cppwinrt@a889be0 (make_ready for pre-completed operations) and microsoft/cppwinrt@1f16ab0 (perfect-forward the value).
The canonical shape is Raymond Chen's series, "Creating an already-completed asynchronous activity in C++/WinRT" (parts 1–9, July 2024): part 1 → part 9. Follow the "next time" chain to the final form (parts 8–9): a winrt::implements type over a small winrt_async_traits table (covering IAsyncAction/IAsyncOperation<T> and their WithProgress variants, plus a failed_async for the error case), no mutex, Completed/Progress handlers fired inline rather than stored. The cppwinrt prototype additionally kept a single-assignment guard on Completed (throw hresult_illegal_delegate_assignment on a second set) to match the coroutine promise contract; worth keeping.
(via Copilot)
Request
A helper that returns an
IAsyncOperation<T>orIAsyncActionalready in theCompletedstate, carrying a fixed result, with no coroutine frame.co_await make_ready(x),.get(), and aCompletedhandler all complete synchronously.Why
Returning an already-known value from an async-typed API today spins up a coroutine frame and its promise/allocation just to hand back a value that's already in hand. A ready-made completed object skips the frame entirely — the common "the answer is cached / trivially available" path.
Where
wil/cppwinrt.h. This was prototyped in microsoft/cppwinrt#1608 and then pulled back out: cppwinrt should stay a pure projection, and the coroutine/async helpers belong in WIL (sylveon on #1608).Implementation
Prototype: microsoft/cppwinrt@a889be0 (
make_readyfor pre-completed operations) and microsoft/cppwinrt@1f16ab0 (perfect-forward the value).The canonical shape is Raymond Chen's series, "Creating an already-completed asynchronous activity in C++/WinRT" (parts 1–9, July 2024): part 1 → part 9. Follow the "next time" chain to the final form (parts 8–9): a
winrt::implementstype over a smallwinrt_async_traitstable (coveringIAsyncAction/IAsyncOperation<T>and theirWithProgressvariants, plus afailed_asyncfor the error case), no mutex,Completed/Progresshandlers fired inline rather than stored. The cppwinrt prototype additionally kept a single-assignment guard onCompleted(throwhresult_illegal_delegate_assignmenton a second set) to match the coroutine promise contract; worth keeping.(via Copilot)