xtd 1.0.0
Loading...
Searching...
No Matches
coroutine_delegate.cpp

Shows how to use coroutine with delegate and task.

#include <xtd/xtd>
class example {
public:
static auto main() async_ {
println("[main], thread {}] -> start", thread::current_thread().managed_thread_id());
auto get_message = delegate<task<string>()> {[] -> task<string> {co_return "Hello, World!";}};
auto get_size = func<task<usize>, string> {[](auto message) -> task<usize> {co_return message.size();}};
auto message = co_await get_message();
auto length = co_await get_size(message);
println("message : {}", message);
println("length : {}", length);
println("[main, thread {}] -> end", thread::current_thread().managed_thread_id());
}
};
startup_(example::main);
// This code produces the following output :
//
// [main], thread 1] -> start
// message : Hello, World!
// length : 13
// [main, thread 4] -> end
#define startup_(...)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:278