Skip to content
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

支持等待 .detach() 创建的协程 #26

Merged
merged 1 commit into from
Oct 15, 2024
Merged

Conversation

microcai
Copy link
Member

当调用 .detach(), 然后不等待它,那么这个 detch 的协程就直接后台跑了。就好像 create_thread
创建了个新线程一样。

当调用 .detach(), 然后使用 co_await 等待它,那么当前协程就等待这个 detach 的协程完成。
就好像调用 std.thread.join() 那样。

@microcai microcai requested a review from EvinceMoi October 15, 2024 06:26
@microcai microcai enabled auto-merge (rebase) October 15, 2024 06:26
@microcai microcai requested a review from Jackarain October 15, 2024 06:26
@microcai microcai added the enhancement New feature or request label Oct 15, 2024
@microcai microcai force-pushed the awaitable-detached-coro branch from 8a9f6e1 to 50a5d1c Compare October 15, 2024 06:54
@microcai microcai disabled auto-merge October 15, 2024 06:55
Copy link
Member

@Jackarain Jackarain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请简述实现原理

Copy link
Member Author

@microcai microcai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就是给 awaitable_detached 添加 await_suspend 和 await_resume , 这样它就能被 co_await 了。

Copy link
Member

@Jackarain Jackarain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是很多代码风格问题,还有一些功能上的问题:
1,co_await 的情况下,也需要考虑返回值。
2,同样也需要考虑异常转发。

include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
tests/test1/test1.cpp Outdated Show resolved Hide resolved
include/ucoro/awaitable.hpp Outdated Show resolved Hide resolved
@microcai
Copy link
Member Author

OK. 等我发第二版

@microcai microcai force-pushed the awaitable-detached-coro branch 4 times, most recently from c1f35be to d3238bf Compare October 15, 2024 09:46
当调用 .detach(), 然后不等待它,那么这个 detch 的协程就直接后台跑了。就好像 create_thread
创建了个新线程一样。

当调用 .detach(), 然后使用 co_await 等待它,那么当前协程就等待这个 detach 的协程完成。
就好像调用 std.thread.join() 那样。
@microcai microcai force-pushed the awaitable-detached-coro branch from d3238bf to c4fac25 Compare October 15, 2024 09:50
@microcai microcai enabled auto-merge (rebase) October 15, 2024 10:28
@microcai microcai disabled auto-merge October 15, 2024 10:28
Copy link
Member

@Jackarain Jackarain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

只有 test 命名稍需改善,其它一切看起来都没问题了。

tests/CMakeLists.txt Show resolved Hide resolved
Copy link
Member

@Jackarain Jackarain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先 Approve,后面再统一修改 tests 的命名问题

@microcai microcai merged commit b077b7b into master Oct 15, 2024
6 checks passed
@microcai microcai deleted the awaitable-detached-coro branch October 15, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants