summaryrefslogtreecommitdiff
path: root/include/mbgl/actor/actor.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/actor/actor.hpp')
-rw-r--r--include/mbgl/actor/actor.hpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/mbgl/actor/actor.hpp b/include/mbgl/actor/actor.hpp
index 810114c513..00e1bb82f8 100644
--- a/include/mbgl/actor/actor.hpp
+++ b/include/mbgl/actor/actor.hpp
@@ -6,6 +6,7 @@
#include <mbgl/util/noncopyable.hpp>
#include <memory>
+#include <future>
namespace mbgl {
@@ -61,6 +62,17 @@ public:
mailbox->push(actor::makeMessage(object, fn, std::forward<Args>(args)...));
}
+ template <typename Fn, class... Args>
+ auto ask(Fn fn, Args&&... args) {
+ // Result type is deduced from the function's return type
+ using ResultType = typename std::result_of<decltype(fn)(Object, Args...)>::type;
+
+ std::promise<ResultType> promise;
+ auto future = promise.get_future();
+ mailbox->push(actor::makeMessage(std::move(promise), object, fn, std::forward<Args>(args)...));
+ return future;
+ }
+
ActorRef<std::decay_t<Object>> self() {
return ActorRef<std::decay_t<Object>>(object, mailbox);
}