await_resume()
to await_result()
By: Mathias Stearn (MongoDB)
Date: 2019-03-10
The coroutine feature recently approved for C++20 defines an API for types that support being co_await
ed, consisting of three methods: await_ready()
, await_suspend()
, and await_resume()
. This paper proposes to rename the last to await_result()
, which better reflects its purpose and effects.
await_resume()
is called even when the coroutine isn’t suspended if await_ready()
returns true
, so there is no resuming to be done.await_suspend()
, but that’s a lie. They are almost completely unrelated.Future
or Task
. When you define the await_resume()
method for such a type, you need to remember that it isn’t called when the coroutine that your are defining is resumed. Instead, it is called when the consuming coroutine resumes, to get the result of this coroutine.Summary: This change makes the Awaitable API more intuitive, therefore easier to teach and learn. This is important because that API is the second layer in the “Gor Table” from section 4.4 of P1362, so it will be the first form of coroutine customization most users will do.
If we want to ease the transition, we can add explicit wording to the TS to work with both names. We would need to either prefer one if both are present, or just make that ill-formed.