From a9ac314a5d28bec2a26cd6889364f81f811d4cd4 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Thu, 20 Jul 2017 19:17:49 +0300 Subject: [core] implement ask pattern in actor --- test/actor/actor.test.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/actor/actor.test.cpp b/test/actor/actor.test.cpp index 3d97469628..2b4c83f566 100644 --- a/test/actor/actor.test.cpp +++ b/test/actor/actor.test.cpp @@ -281,3 +281,27 @@ TEST(Actor, NonConcurrentMailbox) { test.invoke(&Test::end); endedFuture.wait(); } + +TEST(Actor, Ask) { + // Asking for a result + + struct Test { + + Test(ActorRef) {} + + int doubleIt(int i) { + return i * 2; + } + }; + + ThreadPool pool { 2 }; + Actor test(pool); + + auto result = test.ask(&Test::doubleIt, 1); + + ASSERT_TRUE(result.valid()); + + auto status = result.wait_for(std::chrono::seconds(1)); + ASSERT_EQ(std::future_status::ready, status); + ASSERT_EQ(2, result.get()); +} -- cgit v1.2.1