TEST(WorkerThread, LoopVoid) { int callbacks = 0; WorkerThread<void(bool)> worker; auto loop = uv::Loop::Create(); worker.SetLoop(*loop); worker.QueueWorkThen([](bool) {}, [&]() { ++callbacks; loop->Stop(); }, true); auto f = worker.QueueWork([](bool) {}, true); f.get(); loop->Run(); ASSERT_EQ(callbacks, 1); }
TEST(WorkerThread, Loop) { int callbacks = 0; WorkerThread<int(bool)> worker; auto loop = uv::Loop::Create(); worker.SetLoop(*loop); worker.QueueWorkThen([](bool v) -> int { return v ? 1 : 2; }, [&](int v2) { ++callbacks; loop->Stop(); ASSERT_EQ(v2, 1); }, true); auto f = worker.QueueWork([](bool) -> int { return 2; }, true); ASSERT_EQ(f.get(), 2); loop->Run(); ASSERT_EQ(callbacks, 1); }