本文整理汇总了C++中ManualExecutor类的典型用法代码示例。如果您正苦于以下问题:C++ ManualExecutor类的具体用法?C++ ManualExecutor怎么用?C++ ManualExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ManualExecutor类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(WindowExecutor, parallel) {
ManualExecutor executor;
std::vector<int> input;
std::vector<Promise<int>> ps(10);
for (size_t i = 0; i < ps.size(); i++) {
input.emplace_back(i);
}
auto f = collect(
window(&executor, input, [&](int i) { return ps[i].getFuture(); }, 3));
std::vector<std::thread> ts;
boost::barrier barrier(ps.size() + 1);
for (size_t i = 0; i < ps.size(); i++) {
ts.emplace_back([&ps, &barrier, i]() {
barrier.wait();
ps[i].setValue(i);
});
}
barrier.wait();
for (auto& t : ts) {
t.join();
}
executor.drain();
EXPECT_TRUE(f.isReady());
for (size_t i = 0; i < ps.size(); i++) {
EXPECT_EQ(i, f.value()[i]);
}
}
示例2: TEST
TEST(ManualExecutor, runIsStable) {
ManualExecutor x;
size_t count = 0;
auto f1 = [&]() { count++; };
auto f2 = [&]() { x.add(f1); x.add(f1); };
x.add(f2);
x.run();
}
示例3: TEST
TEST(ManualExecutor, advanceBack) {
ManualExecutor x;
size_t count = 0;
x.advance(microseconds(5));
x.schedule([&]{ count++; }, microseconds(6));
EXPECT_EQ(count, 0);
x.advanceTo(x.now() - microseconds(1));
EXPECT_EQ(count, 0);
}
示例4: TEST
TEST(ViaFunc, liftsVoid) {
ManualExecutor x;
int count = 0;
Future<Unit> f = via(&x, [&]{ count++; });
EXPECT_EQ(0, count);
x.run();
EXPECT_EQ(1, count);
}
示例5: TEST
TEST(Coro, Basic2) {
ManualExecutor executor;
auto future = via(&executor, taskVoid());
EXPECT_FALSE(future.await_ready());
executor.drive();
EXPECT_TRUE(future.await_ready());
}