aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/helpers/future_callback.h
blob: 6626dd439d2820074016bfba728f022183f442d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include <library/cpp/actors/core/actor.h>
#include <library/cpp/actors/core/hfunc.h>

namespace NActors {

template <typename EventType>
struct TActorFutureCallback : TActor<TActorFutureCallback<EventType>> {
    using TCallback = std::function<void(TAutoPtr<TEventHandle<EventType>>&)>;
    using TBase = TActor<TActorFutureCallback<EventType>>;
    TCallback Callback;

    static constexpr IActor::EActivityType ActorActivityType() {
        return IActor::EActivityType::ACTOR_FUTURE_CALLBACK;
    }

    TActorFutureCallback(TCallback&& callback)
        : TBase(&TActorFutureCallback::StateWaitForEvent)
        , Callback(std::move(callback))
    {}

    STRICT_STFUNC(StateWaitForEvent,
        HFunc(EventType, Handle)
    )

    void Handle(typename EventType::TPtr ev, const TActorContext& ctx) {
        Callback(ev);
        TBase::Die(ctx);
    }
};

} // NActors