aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2023-06-16 19:16:06 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2023-06-16 19:16:06 +0300
commitb3a917acb08540c7ca714cad59a607aa1e731b19 (patch)
tree40547d176af4ec0272fd1f7101d3630c72227184 /library
parent06f9c4f449aed9cd2eb3996de068b794fa046fc5 (diff)
downloadydb-b3a917acb08540c7ca714cad59a607aa1e731b19.tar.gz
use controller directly instead of actor/events
Diffstat (limited to 'library')
-rw-r--r--library/cpp/actors/core/invoke.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/library/cpp/actors/core/invoke.h b/library/cpp/actors/core/invoke.h
index 931a9767dd..a971f90631 100644
--- a/library/cpp/actors/core/invoke.h
+++ b/library/cpp/actors/core/invoke.h
@@ -107,4 +107,38 @@ namespace NActors {
std::forward<TCallback>(callback), std::forward<TCompletion>(complete));
}
+ template <class TInvokeExecutor>
+ class TScheduledInvokeActivity: public TActor<TScheduledInvokeActivity<TInvokeExecutor>> {
+ private:
+ using TBase = TActor<TScheduledInvokeActivity<TInvokeExecutor>>;
+ const TMonotonic Timestamp;
+ TInvokeExecutor Executor;
+ public:
+ TScheduledInvokeActivity(TInvokeExecutor&& executor, const TMonotonic timestamp)
+ : TBase(&TBase::TThis::StateFunc)
+ , Timestamp(timestamp)
+ , Executor(std::move(executor)) {
+ }
+
+ void StateFunc(STFUNC_SIG) {
+ Y_VERIFY(ev->GetTypeRewrite() == TEvents::TSystem::Wakeup);
+ auto g = TBase::PassAwayGuard();
+ Executor();
+ }
+
+ void Registered(TActorSystem* sys, const TActorId& owner) override {
+ sys->Schedule(Timestamp, new IEventHandle(TEvents::TSystem::Wakeup, 0, TBase::SelfId(), owner, nullptr, 0));
+ }
+ };
+
+ template<class TInvokeExecutor>
+ void ScheduleInvokeActivity(TInvokeExecutor&& executor, const TDuration d) {
+ TActivationContext::Register(new TScheduledInvokeActivity<TInvokeExecutor>(std::move(executor), TMonotonic::Now() + d));
+ }
+
+ template<class TInvokeExecutor>
+ void ScheduleInvokeActivity(TInvokeExecutor&& executor, const TMonotonic timestamp) {
+ TActivationContext::Register(new TScheduledInvokeActivity<TInvokeExecutor>(std::move(executor), timestamp));
+ }
+
} // NActors