Last active
May 29, 2024 02:36
-
-
Save lawrencefmm/41627d18d83d033fa44dfe2a655bf77b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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