Commit 6b95c53d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Rename co_schedule to co_reschedule_on_current_executor

Summary: [Folly] Rename `co_schedule` to `co_reschedule_on_current_executor`, which is longer but which more clearly identifies the behavior.

Reviewed By: lewissbaker

Differential Revision: D15215844

fbshipit-source-id: aada82e8985224608415ee5458ac8138ce13f8d0
parent 5af16267
...@@ -25,7 +25,7 @@ namespace coro { ...@@ -25,7 +25,7 @@ namespace coro {
namespace detail { namespace detail {
class co_schedule_t { class co_reschedule_on_current_executor_t {
class Awaiter { class Awaiter {
folly::Executor::KeepAlive<> executor_; folly::Executor::KeepAlive<> executor_;
...@@ -50,7 +50,7 @@ class co_schedule_t { ...@@ -50,7 +50,7 @@ class co_schedule_t {
friend Awaiter co_viaIfAsync( friend Awaiter co_viaIfAsync(
folly::Executor::KeepAlive<> executor, folly::Executor::KeepAlive<> executor,
co_schedule_t) { co_reschedule_on_current_executor_t) {
return Awaiter{std::move(executor)}; return Awaiter{std::move(executor)};
} }
}; };
...@@ -69,12 +69,13 @@ class co_schedule_t { ...@@ -69,12 +69,13 @@ class co_schedule_t {
// for (int i = 0; i < 1'000'000; ++i) { // for (int i = 0; i < 1'000'000; ++i) {
// // Periodically reschedule to the executor. // // Periodically reschedule to the executor.
// if ((i % 1024) == 1023) { // if ((i % 1024) == 1023) {
// co_await folly::coro::co_schedule; // co_await folly::coro::co_reschedule_on_current_executor;
// } // }
// doSomeWork(i); // doSomeWork(i);
// } // }
// } // }
inline constexpr detail::co_schedule_t co_schedule; inline constexpr detail::co_reschedule_on_current_executor_t
co_reschedule_on_current_executor;
} // namespace coro } // namespace coro
} // namespace folly } // namespace folly
...@@ -396,7 +396,7 @@ TEST(CollectAllRange, RangeOfNonVoid) { ...@@ -396,7 +396,7 @@ TEST(CollectAllRange, RangeOfNonVoid) {
using namespace std::literals::chrono_literals; using namespace std::literals::chrono_literals;
int x = count++; int x = count++;
if ((x % 20) == 0) { if ((x % 20) == 0) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
} }
co_return x; co_return x;
}; };
...@@ -500,7 +500,7 @@ TEST(CollectAllWindowed, ConcurrentTasks) { ...@@ -500,7 +500,7 @@ TEST(CollectAllWindowed, ConcurrentTasks) {
[&]() -> Generator<Task<std::string>&&> { [&]() -> Generator<Task<std::string>&&> {
for (int i = 0; i < 10'000; ++i) { for (int i = 0; i < 10'000; ++i) {
co_yield[](int i)->Task<std::string> { co_yield[](int i)->Task<std::string> {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
co_return folly::to<std::string>(i); co_return folly::to<std::string>(i);
} }
(i); (i);
...@@ -527,7 +527,7 @@ TEST(CollectAllWindowed, WithGeneratorOfTaskOfValue) { ...@@ -527,7 +527,7 @@ TEST(CollectAllWindowed, WithGeneratorOfTaskOfValue) {
// Reschedule a variable number of times so that tasks may complete out of // Reschedule a variable number of times so that tasks may complete out of
// order. // order.
for (int i = 0; i < index % 5; ++i) { for (int i = 0; i < index % 5; ++i) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
} }
--activeCount; --activeCount;
...@@ -565,7 +565,7 @@ TEST(CollectAllWindowed, WithGeneratorOfTaskOfVoid) { ...@@ -565,7 +565,7 @@ TEST(CollectAllWindowed, WithGeneratorOfTaskOfVoid) {
auto makeTask = [&]() -> folly::coro::Task<void> { auto makeTask = [&]() -> folly::coro::Task<void> {
auto count = ++activeCount; auto count = ++activeCount;
CHECK_LE(count, maxConcurrency); CHECK_LE(count, maxConcurrency);
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
--activeCount; --activeCount;
++completedCount; ++completedCount;
}; };
...@@ -591,7 +591,7 @@ TEST(CollectAllWindowed, VectorOfVoidTask) { ...@@ -591,7 +591,7 @@ TEST(CollectAllWindowed, VectorOfVoidTask) {
int count = 0; int count = 0;
auto makeTask = [&]() -> folly::coro::Task<void> { auto makeTask = [&]() -> folly::coro::Task<void> {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
++count; ++count;
}; };
...@@ -611,7 +611,7 @@ TEST(CollectAllWindowed, VectorOfValueTask) { ...@@ -611,7 +611,7 @@ TEST(CollectAllWindowed, VectorOfValueTask) {
int count = 0; int count = 0;
auto makeTask = [&](int i) -> folly::coro::Task<std::unique_ptr<int>> { auto makeTask = [&](int i) -> folly::coro::Task<std::unique_ptr<int>> {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
++count; ++count;
co_return std::make_unique<int>(i); co_return std::make_unique<int>(i);
}; };
...@@ -640,11 +640,11 @@ TEST(CollectAllWindowed, PartialFailure) { ...@@ -640,11 +640,11 @@ TEST(CollectAllWindowed, PartialFailure) {
co_yield[](int i)->folly::coro::Task<int> { co_yield[](int i)->folly::coro::Task<int> {
using namespace std::literals::chrono_literals; using namespace std::literals::chrono_literals;
if (i == 3) { if (i == 3) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
throw ErrorA{}; throw ErrorA{};
} else if (i == 7) { } else if (i == 7) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
throw ErrorB{}; throw ErrorB{};
} }
co_return i; co_return i;
...@@ -671,11 +671,11 @@ TEST(CollectAllTryWindowed, PartialFailure) { ...@@ -671,11 +671,11 @@ TEST(CollectAllTryWindowed, PartialFailure) {
co_yield[](int i)->folly::coro::Task<int> { co_yield[](int i)->folly::coro::Task<int> {
using namespace std::literals::chrono_literals; using namespace std::literals::chrono_literals;
if (i == 3) { if (i == 3) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
throw ErrorA{}; throw ErrorA{};
} else if (i == 7) { } else if (i == 7) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
throw ErrorB{}; throw ErrorB{};
} }
co_return i; co_return i;
...@@ -707,7 +707,7 @@ TEST(CollectAllTryWindowed, GeneratorFailure) { ...@@ -707,7 +707,7 @@ TEST(CollectAllTryWindowed, GeneratorFailure) {
++active; ++active;
++started; ++started;
for (int j = 0; j < (i % 3); ++j) { for (int j = 0; j < (i % 3); ++j) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
} }
--active; --active;
}; };
......
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
TEST(Task, CoSchedule) { TEST(Task, CoRescheduleOnCurrentExecutor) {
std::vector<int> results; std::vector<int> results;
folly::coro::blockingWait(folly::coro::collectAll( folly::coro::blockingWait(folly::coro::collectAll(
folly::coro::co_invoke([&]() -> folly::coro::Task<void> { folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
for (int i = 0; i <= 10; i += 2) { for (int i = 0; i <= 10; i += 2) {
if (i == 6) { if (i == 6) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
} }
results.push_back(i); results.push_back(i);
} }
...@@ -39,7 +39,7 @@ TEST(Task, CoSchedule) { ...@@ -39,7 +39,7 @@ TEST(Task, CoSchedule) {
folly::coro::co_invoke([&]() -> folly::coro::Task<void> { folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
for (int i = 1; i < 10; i += 2) { for (int i = 1; i < 10; i += 2) {
if (i == 7) { if (i == 7) {
co_await folly::coro::co_schedule; co_await folly::coro::co_reschedule_on_current_executor;
} }
results.push_back(i); results.push_back(i);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment