#include #include #include #include #include #include using namespace mbgl; using namespace std::chrono_literals; TEST(ActorRef, CanOutliveActor) { // An ActorRef can outlive its actor. Doing does not extend the actor's lifetime. // Sending a message to an ActorRef whose actor has died is a no-op. struct Test { bool& died; Test(ActorRef, bool& died_) : died(died_) { } ~Test() { died = true; } void receive() { FAIL(); } }; ThreadPool pool { 1 }; bool died = false; ActorRef test = [&] () { return Actor(pool, std::ref(died)).self(); }(); EXPECT_TRUE(died); test.invoke(&Test::receive); }