Article

How can I pass more than one parameter to co_await?

The Old New Thing ·The Old New Thing ·Published 2026-11-12 ·5 min read

This article discusses how to pass additional parameters to the co_await operator in C++. It explains that since co_await only accepts one parameter, you need to wrap the awaitable object and its parameters into a larger object.

From the article

Suppose you have an awaitable object, but you want the caller to pass a bonus parameter when they do a co_await . For example, you may want the caller to be able to pass a priority or a timeout or something else that modifies how the await occurs.

struct Widget { ⟦ ... other stuff ... ⟧ bool await_ready() const { return ⟦ ... ⟧; } bool await_suspend(std::coroutine_handle<> handle) { int priority = ??? how do I get a priority ???; return internal_start(handle, priority); } auto await_resume() { return ⟦ ... ⟧; } }; // This doesn't work auto result = co_await (widget, priority); So how do you pass two parameters to co_await so they can be used in await_ suspend ?

It’s a trick question. You can’t. The co_await operator takes only one parameter.


Share this resource


Discovered 2026-11-13 Source The Old New Thing Archive 2026-11 →