future_callback.h 893 B

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include <library/cpp/actors/core/actor.h>
  3. #include <library/cpp/actors/core/hfunc.h>
  4. namespace NActors {
  5. template <typename EventType>
  6. struct TActorFutureCallback : TActor<TActorFutureCallback<EventType>> {
  7. using TCallback = std::function<void(TAutoPtr<TEventHandle<EventType>>&)>;
  8. using TBase = TActor<TActorFutureCallback<EventType>>;
  9. TCallback Callback;
  10. static constexpr IActor::EActivityType ActorActivityType() {
  11. return IActor::EActivityType::ACTOR_FUTURE_CALLBACK;
  12. }
  13. TActorFutureCallback(TCallback&& callback)
  14. : TBase(&TActorFutureCallback::StateWaitForEvent)
  15. , Callback(std::move(callback))
  16. {}
  17. STRICT_STFUNC(StateWaitForEvent,
  18. HFunc(EventType, Handle)
  19. )
  20. void Handle(typename EventType::TPtr ev, const TActorContext& ctx) {
  21. Callback(ev);
  22. TBase::Die(ctx);
  23. }
  24. };
  25. } // NActors