22 template <
class Object>
27 weakMailbox(
std::move(weakMailbox_)) {
30 template <
typename Fn,
class... Args>
31 void invoke(Fn fn, Args&&... args)
const {
32 if (
auto mailbox = weakMailbox.lock()) {
37 template <
typename Fn,
class... Args>
38 auto ask(Fn fn, Args&&... args)
const {
40 using ResultType = std::invoke_result_t<decltype(fn),
Object, Args...>;
42 std::promise<ResultType> promise;
43 auto future = promise.get_future();
45 if (
auto mailbox = weakMailbox.lock()) {
48 std::move(promise), *
object, fn, std::forward<Args>(args)...
52 promise.set_exception(std::make_exception_ptr(std::runtime_error(
"Actor has gone away")));
60 std::weak_ptr<Mailbox> weakMailbox;
void invoke(Fn fn, Args &&... args) const
ActorRef(Object &object_, std::weak_ptr< Mailbox > weakMailbox_)
auto ask(Fn fn, Args &&... args) const
std::unique_ptr< Message > makeMessage(Object &object, MemberFn memberFn, Args &&... args)
constexpr ObjectType Object