Skip to content

Instantly share code, notes, and snippets.

@lawrencefmm
Last active May 29, 2024 02:36
Show Gist options
  • Save lawrencefmm/41627d18d83d033fa44dfe2a655bf77b to your computer and use it in GitHub Desktop.
Save lawrencefmm/41627d18d83d033fa44dfe2a655bf77b to your computer and use it in GitHub Desktop.
Chat Fun() // #A Wrapper type Chat containing the promise type
{
co_yield "Olá!\n"s; // #B Calls promise_type.yield_value
std::cout << co_await std::string{}; // #C Calls promise_type.await_transform
co_return "Aqui!\n"s; // #D Calls promise_type.return_value
}
int main()
{
Chat chat = Fun(); // #E Creation of the coroutine
std::cout << chat.listen(); // #F Trigger the machine
chat.answer("Onde você está?\n"s); // #G Send data into the coroutine
std::cout << chat.listen(); // #H Wait for more data from the coroutine
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment