@@ -78,10 +78,7 @@ class ReactorNode :
7878
7979 // First blocking event is not initiated by Tick() but after loop creation.
8080 NodeBase<D>* p = mainLoop_.get ();
81-
82- assert (p != nullptr );
83-
84- Engine::OnNodeAttach (*this , *p);
81+ doAttach (p);
8582
8683 ++depCount_;
8784 }
@@ -101,8 +98,7 @@ class ReactorNode :
10198
10299 if (p != nullptr )
103100 {
104- Engine::OnDynamicNodeAttach (*this , *p, *turnPtr_);
105- ++depCount_;
101+ doDynAttach (p);
106102 }
107103 else
108104 {
@@ -126,10 +122,7 @@ class ReactorNode :
126122 while (! checkEvent (events))
127123 (*curOutPtr_)(nullptr );
128124
129- assert (turnPtr_ != nullptr );
130-
131- Engine::OnDynamicNodeDetach (*this , *events, *turnPtr_);
132- --depCount_;
125+ doDynDetach (events.get ());
133126
134127 auto index = offsets_[reinterpret_cast <uintptr_t >(events.get ())]++;
135128 return events->Events ()[index];
@@ -147,8 +140,7 @@ class ReactorNode :
147140 {
148141 // Non-dynamic attach in case first loop until is encountered before the loop was
149142 // suspended for the first time.
150- Engine::OnNodeAttach (*this , *eventsPtr);
151- ++depCount_;
143+ doAttach (eventsPtr.get ());
152144 }
153145
154146 // Don't enter loop if event already present
@@ -190,18 +182,20 @@ class ReactorNode :
190182 --depCount_;
191183 }
192184
193- // template <typename S>
194- // S& Get(const std::shared_ptr<SignalNode<D,S>>& sig)
195- // {
196- // // Attach to target signal node
197- // (*curOutPtr_)(sig.get());
185+ template <typename S>
186+ const S& Get (const std::shared_ptr<SignalNode<D,S>>& sigPtr)
187+ {
188+ // Do dynamic attach followed by attach if Get() happens during a turn.
189+ if (turnPtr_ != nullptr )
190+ {
191+ // Request attach
192+ (*curOutPtr_)(sigPtr.get ());
198193
199- // Engine::OnDynamicNodeDetach(*this, *events, *turnPtr_ );
200- // --depCount_;
194+ doDynDetach (sigPtr. get () );
195+ }
201196
202- // auto index = offsets_[reinterpret_cast<uintptr_t>(events.get())]++;
203- // return events->Events()[index];
204- // }
197+ return sigPtr->ValueRef ();
198+ }
205199
206200private:
207201 template <typename E>
@@ -216,6 +210,38 @@ class ReactorNode :
216210 return offsets_[index] < events->Events ().size ();
217211 }
218212
213+ void doAttach (NodeBase<D>* nodePtr)
214+ {
215+ assert (nodePtr != nullptr );
216+ assert (turnPtr_ == nullptr );
217+ Engine::OnNodeAttach (*this , *nodePtr);
218+ ++depCount_;
219+ }
220+
221+ void doDetach (NodeBase<D>* nodePtr)
222+ {
223+ assert (nodePtr != nullptr );
224+ assert (turnPtr_ == nullptr );
225+ Engine::OnNodeDetach (*this , *nodePtr);
226+ --depCount_;
227+ }
228+
229+ void doDynAttach (NodeBase<D>* nodePtr)
230+ {
231+ assert (nodePtr != nullptr );
232+ assert (turnPtr_ != nullptr );
233+ Engine::OnDynamicNodeAttach (*this , *nodePtr, *turnPtr_);
234+ ++depCount_;
235+ }
236+
237+ void doDynDetach (NodeBase<D>* nodePtr)
238+ {
239+ assert (nodePtr != nullptr );
240+ assert (turnPtr_ != nullptr );
241+ Engine::OnDynamicNodeDetach (*this , *nodePtr, *turnPtr_);
242+ --depCount_;
243+ }
244+
219245 std::function<void (TContext)> func_;
220246
221247 PullT mainLoop_;
0 commit comments