aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2022-10-21 09:26:27 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2022-10-21 09:26:27 +0300
commitcf9888c00bf8a838837c09c830efa110d0bd31e6 (patch)
tree21d6491055cf8fc738368e7f9c8ecda7f3a81fcb /library/cpp
parentb7cbacab05926fc7ad4856a02481082dfbbb9e68 (diff)
downloadydb-cf9888c00bf8a838837c09c830efa110d0bd31e6.tar.gz
use context constructor and sender guard instead of method with a lot of arguments
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/actors/core/actor.h41
-rw-r--r--library/cpp/actors/core/actorsystem.h5
2 files changed, 41 insertions, 5 deletions
diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h
index ca7bb83d087..a1a17b54bbd 100644
--- a/library/cpp/actors/core/actor.h
+++ b/library/cpp/actors/core/actor.h
@@ -323,6 +323,47 @@ namespace NActors {
}
public:
+ template <class TEventBase>
+ class TEventSenderFromActor: ::TNonCopyable {
+ private:
+ ui32 Flags = 0;
+ ui64 Cookie = 0;
+ const TActorIdentity SenderId;
+ NWilson::TTraceId TraceId = {};
+ std::unique_ptr<TEventBase> Event;
+ public:
+ template <class... Types>
+ TEventSenderFromActor(const IActor* owner, Types&&... args)
+ : SenderId(owner->SelfId())
+ , Event(new TEventBase(std::forward<Types>(args)...)) {
+
+ }
+
+ TEventSenderFromActor& SetFlags(const ui32 flags) {
+ Flags = flags;
+ return *this;
+ }
+
+ TEventSenderFromActor& SetCookie(const ui64 value) {
+ Cookie = value;
+ return *this;
+ }
+
+ TEventSenderFromActor& SetTraceId(NWilson::TTraceId&& value) {
+ TraceId = std::move(value);
+ return *this;
+ }
+
+ bool SendTo(const TActorId& recipient) {
+ return SenderId.Send(recipient, Event.release(), Flags, Cookie, std::move(TraceId));
+ }
+ };
+
+ template <class TEvent, class... Types>
+ TEventSenderFromActor<TEvent> Sender(Types&&... args) const {
+ return TEventSenderFromActor<TEvent>(this, std::forward<Types>(args)...);
+ }
+
virtual ~IActor() {
} // must not be called for registered actors, see Die method instead
diff --git a/library/cpp/actors/core/actorsystem.h b/library/cpp/actors/core/actorsystem.h
index b24e923e085..dc0bdc370fa 100644
--- a/library/cpp/actors/core/actorsystem.h
+++ b/library/cpp/actors/core/actorsystem.h
@@ -270,11 +270,6 @@ namespace NActors {
bool SendWithContinuousExecution(TAutoPtr<IEventHandle> ev) const;
bool Send(const TActorId& recipient, IEventBase* ev, ui32 flags = 0) const;
- template <class TEvent, class... Types>
- bool SendToActorId(const TActorId& recipient, Types... args) const {
- return Send(recipient, new TEvent(args...), 0);
- }
-
/**
* Schedule one-shot event that will be send at given time point in the future.
*