-
Notifications
You must be signed in to change notification settings - Fork 239
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
feat: add Future.setResumeBySchedule interface #357
Conversation
额,我现在有权限直接merge了 |
async_simple/coro/FutureAwaiter.h
Outdated
} | ||
ex->checkin(continuation, ctx); | ||
return; | ||
} |
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.
更风格一致的 API 设计可能是这样的:
co_await fut; // check in by default
co_await ResumeBySchedule(std::move(fut)); // resume by schedule
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.
我在想有些executor的checkout,checkin可能是需要配对执行,比如可能带了引用计数。这种改动是否可能导致checkout了但是没checkin
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.
我在想有些executor的checkout,checkin可能是需要配对执行,比如可能带了引用计数。这种改动是否可能导致checkout了但是没checkin
这种问题,只能由用户来保证吧,不然的话设计受到的约束和需要的检查太多了。作为一个库我们只解决自己能够解决的问题。
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.
嗯,我看到了,你这里resume_by_schedule true的时候没有checkout,没问题的
fut.setResumeBySchedule(); | ||
sum(1, 1, [pr = std::move(pr)](int val) mutable { pr.setValue(val); }); | ||
auto val = co_await std::move(fut); | ||
EXPECT_EQ(2, val); |
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.
这个足够测试我们想要的语义吗?我感觉要不写一个 mock 的 Executor 然后 check 足够 mock executor 的 checkin 不会执行
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.
好,我改一下API然后加测试吧
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.
我在想要不要直接在SimpleExecutor上加一些统计信息得成员变量,还是Mock一个Executor。
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.
个人更偏好mock些,但也没什么强的理由阻止在simple executor里加
OK,那像 #353 这种比较 trivial 且你有非常强信心是正确的 patch,你就可以直接 merge 了 |
我记得promise里有个forceSched就是控制这个的 |
哦哦,forceSched说的是一定要走一下调度。这里看起来是说控制可以不checkin回到之前的线程 |
docs/docs.en/Future.md
Outdated
the Lazy lives in. | ||
If the Future has set Executor already, the Executor would decide when will the Lazy to be resumed. Note that it wouldn't change the executor the Lazy lives in. | ||
|
||
When binding Executor, `co_ Await` Future will resume Lazy through the ` Executor.checkin` interface by default, and users can explicitly specify that Future resume Lazy through the `Executor.schedule` interface by calling `Future.setResumeBySchedule()`. |
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.
co_ Await -> co_await?
e203b39
to
497aa67
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.
LGTM. Thanks.
Why
co_await future
resume的时候是走schedule还是checkin,应该由用户来决定,现在的实现默认走checkin,很多情况下是没必要的。注:不应该通过不实现Executor的checkin接口来达到上述目的,因为很可能一些Future需要checkin而一些Future不需要。
What is changing
no incompatible changes
Example