这行代码在协程中起到了挂起(Suspend)协程执行的作用。它调用 Awaiter 类型的对象的 await_suspend ...
然后会根据是否有对可等待体的operator co_await重载来生成一个等待器(awaiter) 。
type>();public:usingawaiter_type=std::conditional<overwrite_operator_co_await<A>,decltype(std::f...
Awaiter constructed work = nullptr; The analyses for the no-suspend path and the abandonment path are the same as last time. The extra decision in the center path is deciding when to close the work item. I decided to do it inresume_node_callback: I definitely want the work item to be...
error C2039: 'await_resume': is not a member of 'simple_task<Result>::cannot_await_lvalue_use_std_move' That’s a little better. Okay, so I left a bunch of...inside the body ofoperator co_await &&. We need to move thepromise_ptrinto the awaiter, and that means having to do ...
Awaiter还有另外两种方法。这些方法是语言所要求的。 await_ready是一种优化。如果返回true,则co_await不会暂停该函数。比如说我将return false改成return true。这个例子的协程就不会停止。会一直打印: 当然,改写await_suspend恢复(或不挂起)当前协程来实现相同的效果。比如说这种写法: ...
这是GCC中协程实现中的一个编译器错误,因为当前的标准草案中没有任何内容禁止await_resume的自定义/复合...
是的,它是安全的。std::jthread的构造函数是synchronization。
是的,它是安全的。std::jthread的构造函数是synchronization。
auto final_suspend() noexcept { return final_awaiter(); } void unhandled_exception() { std::terminate(); } }; using handle_type = std::experimental::coroutine_handle<promise_type>; handle_type coro; MyFuture(handle_type h) : coro(h) {} ...