Skip to content

Commit b532ad3

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Use co_withExecutor in feed_ranking_infra/serving_eval/RankLlmIValueDataEnricher.cpp +5
Summary: `yourTask().scheduleOn(ex)` is deprecated in favor of `co_withExecutor(ex, yourTask())` For `Task`, both forms are equivalent, but `co_withExecutor` makes it much easier to migrate to the [lifetime-safe `NowTask`](https://fb.prod.workplace.com/groups/192968587972839/posts/1784449738824708) (and upcoming `SafeTask`). Thanks to [C++ ADL](https://en.cppreference.com/w/cpp/language/adl.html), you can write simply `co_withExecutor`; it does not *have* to be qualified with the namespace `folly::coro::`. [This post](https://fb.prod.workplace.com/groups/192968587972839/posts/1693720697897613) explains the safety benefits of `co_withExecutor`. Moreover, the new name better aligns with the other `folly::coro` protocol of `co_withCancellation()`. This diff generated with: ``` fbpython fbcode/scripts/rbarnes/schedule_on_fixer.py ``` - If you approve of this diff, please use the "Accept & Ship" button :-) Reviewed By: meyering Differential Revision: D77751576 fbshipit-source-id: 71a6a7e4f78494decb93b5bf8afa1382f94d71e9
1 parent 979605d commit b532ad3

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

third-party/folly/src/folly/coro/AsyncScope.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ namespace coro {
6363
// }
6464
//
6565
// folly::coro::AsyncScope scope;
66-
// scope.add(processEvent(ev1).scheduleOn(folly::getGlobalCPUExecutor()));
67-
// scope.add(processEvent(ev2).scheduleOn(folly::getGlobalCPUExecutor()));
68-
// scope.add(processEvent(ev3).scheduleOn(folly::getGlobalCPUExecutor()));
69-
// co_await scope.joinAsync();
66+
// scope.add(co_withExecutor(folly::getGlobalCPUExecutor(),
67+
// processEvent(ev1)));
68+
// scope.add(co_withExecutor(folly::getGlobalCPUExecutor(),
69+
// processEvent(ev2)));
70+
// scope.add(co_withExecutor(folly::getGlobalCPUExecutor(),
71+
// processEvent(ev3))); co_await scope.joinAsync();
7072
//
7173
class AsyncScope {
7274
public:
@@ -373,7 +375,7 @@ class CancellableAsyncScope {
373375
*/
374376
template <class T>
375377
folly::coro::Task<void> co_schedule(folly::coro::Task<T>&& task) {
376-
add(std::move(task).scheduleOn(co_await co_current_executor));
378+
add(co_withExecutor(co_await co_current_executor, std::move(task)));
377379
co_return;
378380
}
379381

third-party/folly/src/folly/coro/Collect-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ auto makeUnorderedAsyncGeneratorImpl(
269269
state->pipe.write(std::move(result));
270270
}(static_cast<decltype(semiAwaitable)&&>(semiAwaitable), sharedState);
271271
if constexpr (std::is_same_v<AsyncScope, folly::coro::AsyncScope>) {
272-
scopeParam.add(
273-
co_withCancellation(cancelToken, std::move(task)).scheduleOn(ex));
272+
scopeParam.add(co_withExecutor(
273+
ex, co_withCancellation(cancelToken, std::move(task))));
274274
} else {
275275
static_assert(std::is_same_v<AsyncScope, CancellableAsyncScope>);
276276
scopeParam.add(std::move(task).scheduleOn(ex), cancelToken);

third-party/folly/src/folly/coro/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ folly::coro::Task<int> taskSlow43() {
1818

1919
int main() {
2020
...
21-
CHECK_EQ(43, folly::coro::blockingWait(taskSlow43().scheduleOn(
22-
folly::getGlobalCPUExecutor().get())));
21+
CHECK_EQ(43, folly::coro::blockingWait(co_withExecutor(
22+
folly::getGlobalCPUExecutor().get(), taskSlow43())));
2323
...
2424
}
2525
```
@@ -87,7 +87,7 @@ void runCoroutine1() {
8787
// coroutine arguments are captured here, not when we start the coroutine
8888
auto task = checkArg(arg42);
8989
arg42 = 43;
90-
folly::coro::blockingWait(std::move(task).scheduleOn(folly::getCPUExecutor().get()));
90+
folly::coro::blockingWait(co_withExecutor(folly::getCPUExecutor().get(), std::move(task)));
9191
}
9292

9393
void runCoroutine2() {
@@ -124,7 +124,7 @@ folly::coro::Task<void> bar(folly::CPUThreadPoolExecutor* otherExecutor) {
124124

125125
// Launches foo() on 'otherExecutor' and when it's done resumes this
126126
// coroutine on whatever executor bar() was launched on.
127-
co_await foo().scheduleOn(otherExecutor);
127+
co_await co_withExecutor(otherExecutor, foo());
128128
}
129129
```
130130

third-party/folly/src/folly/coro/ScopeExit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class co_scope_exit_fn {
348348
///
349349
/// // Do some complicated, potentially throwing work using the AsyncScope
350350
/// auto ex = co_await co_current_executor;
351-
/// asyncScope->add(someTask(std::move(inputs)).scheduleOn(ex));
351+
/// asyncScope->add(co_withExecutor(ex, someTask(std::move(inputs))));
352352
/// }
353353
///
354354
/// The body of the coroutine passed to co_scope_exit will be executed when the

0 commit comments

Comments
 (0)