-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
删除 awaitable_detached<> 类。减少代码重复 #40
Conversation
少了这么多代码 |
是的 |
include/ucoro/awaitable.hpp
Outdated
@@ -371,19 +281,28 @@ namespace ucoro | |||
{ | |||
using promise_type = awaitable_promise<T>; | |||
|
|||
explicit awaitable(std::coroutine_handle<promise_type> h) : current_coro_handle_(h) | |||
explicit awaitable(std::coroutine_handle<promise_type> h) | |||
: current_coro_handle_(h) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里混用了空格和tab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
除了格式和错别字,我看没别的问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式和错别字
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该是callee,错别字
是哦!
a3c3853
to
44b73eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已更新了。
713bad9
to
c836bc2
Compare
awaitable_detached 自从支持自身被 co_await 后,代码变得越来越像 awaitable<T> 相似度极高。 既然如此,不如合并代码。 detach 的时候,创建一个新的 awaitable<>。 有没有 detach 其实根本原因在于有没有被 co_await. 因此,在 析构函数里,判断是不是 done() 即可知道有没有被 co_await 过了。 如果没有被 co_await 过,则是 detach 模式。在析构里把协程给 resume 起来。 由于析构的时候没有进行 destroy 操作,因此需要在 final_awaiter 里进行清理。 现在 final_awaiter<T> 的部分清理逻辑本身就是从 awaitable_detached::promise_type::final_awaiter 里合并进来的。 同时detach 模式使用 awaitable<T> 后,也修正了 detach 模式下吞异常的问题。
c836bc2
to
0898929
Compare
awaitable_detached 自从支持自身被 co_await 后,代码变得越来越像 awaitable
相似度极高。
既然如此,不如合并代码。 detach 的时候,创建一个新的 awaitable<>。
有没有 detach 其实根本原因在于有没有被 co_await.
因此,在 析构函数里,判断是不是 done() 即可知道有没有被 co_await 过了。
如果没有被 co_await 过,则是 detach 模式。在析构里把协程给 resume 起来。
由于析构的时候没有进行 destroy 操作,因此需要在 final_awaiter 里进行清理。
现在 final_awaiter 的部分清理逻辑本身就是从
awaitable_detached::promise_type::final_awaiter 里合并进来的。
同时detach 模式使用 awaitable 后,也修正了 detach 模式下吞异常的问题。