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

feat: add Future.setResumeBySchedule interface #357

Merged
merged 1 commit into from
Jan 6, 2024

Conversation

chloro-pn
Copy link
Collaborator

Why

co_await future resume的时候是走schedule还是checkin,应该由用户来决定,现在的实现默认走checkin,很多情况下是没必要的。
注:不应该通过不实现Executor的checkin接口来达到上述目的,因为很可能一些Future需要checkin而一些Future不需要。

What is changing

no incompatible changes

Example

@chloro-pn
Copy link
Collaborator Author

额,我现在有权限直接merge了

}
ex->checkin(continuation, ctx);
return;
}
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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

这种问题,只能由用户来保证吧,不然的话设计受到的约束和需要的检查太多了。作为一个库我们只解决自己能够解决的问题。

Copy link
Collaborator

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);
Copy link
Collaborator

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 不会执行

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

好,我改一下API然后加测试吧

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

我在想要不要直接在SimpleExecutor上加一些统计信息得成员变量,还是Mock一个Executor。

Copy link
Collaborator

Choose a reason for hiding this comment

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

个人更偏好mock些,但也没什么强的理由阻止在simple executor里加

@ChuanqiXu9
Copy link
Collaborator

额,我现在有权限直接merge了

OK,那像 #353 这种比较 trivial 且你有非常强信心是正确的 patch,你就可以直接 merge 了

@RainMark
Copy link
Collaborator

RainMark commented Jan 3, 2024

我记得promise里有个forceSched就是控制这个的

@RainMark
Copy link
Collaborator

RainMark commented Jan 3, 2024

哦哦,forceSched说的是一定要走一下调度。这里看起来是说控制可以不checkin回到之前的线程

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()`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

co_ Await -> co_await?

Copy link
Collaborator

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@ChuanqiXu9 ChuanqiXu9 merged commit 90f56d9 into alibaba:main Jan 6, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants