diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-07-20 19:17:49 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-07-24 19:30:02 +0300 |
commit | a9ac314a5d28bec2a26cd6889364f81f811d4cd4 (patch) | |
tree | b1622c574ee1bc659cd11ab24f3ab16098326eca /test | |
parent | 3364992be94364a6e8b302124db53aeed5d99c15 (diff) | |
download | qtlocation-mapboxgl-a9ac314a5d28bec2a26cd6889364f81f811d4cd4.tar.gz |
[core] implement ask pattern in actor
Diffstat (limited to 'test')
-rw-r--r-- | test/actor/actor.test.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
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<Test>) {} + + int doubleIt(int i) { + return i * 2; + } + }; + + ThreadPool pool { 2 }; + Actor<Test> 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()); +} |