Skip to content

Feature request: Overriding "resume in same apartment" behavior for co_await IAsyncXxx #1355

@oldnewthing

Description

@oldnewthing

Version

2.0.230706.1

Summary

By default co_await IAsyncXxx resumes in the same COM apartment. Sometimes, this is not desirable behavior. In C#, you can use ConfigureAwait(false) to disable the resume-in-same-apartment behavior. C++/WinRT would benefit from having a corresponding capability.

A wil-based version was implemented in microsoft/wil#325 but @kennykerr allowd this to be added to core C++/WinRT since it greatly simplifies the implementation, and prevents it from falling out of sync.

Reproducible example

#include <winrt/Windows.Foundation.h>

using namespace winrt;
using namespace winrt::Windows::Foundation;

extern IAsyncAction Something();

IAsyncAction Example()
{
    // This co_await resumes in the same apartment.
    co_await Something();

    // This co_await is permitted to resume in any apartment.
    co_await winrt::resume_agile(Something());
}

Additional comments

The name resume_agile is up for debate, as is the preference for a free function or a member function. See the PR for details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions