Skip to content

Commit 57004a2

Browse files
committed
Added explicit Continuations.
Before, all input in observer nodes to reactives of the current domain was captured as a continuation. Input to other domains was not allowed. Now, MakeContinuation can be used to create explicit continuations. Each continuation is processed as a transaction. Continuations to other domains are supported.
1 parent ae4b597 commit 57004a2

5 files changed

Lines changed: 605 additions & 191 deletions

File tree

include/react/Domain.h

Lines changed: 134 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
#include <memory>
1515
#include <utility>
1616

17+
#include "react/detail/IReactiveEngine.h"
1718
#include "react/detail/ReactiveInput.h"
19+
#include "react/detail/graph/ContinuationNodes.h"
1820

1921
#ifdef REACT_ENABLE_LOGGING
2022
#include "react/logging/EventLog.h"
2123
#include "react/logging/EventRecords.h"
2224
#endif //REACT_ENABLE_LOGGING
2325

24-
#include "react/detail/IReactiveEngine.h"
2526
#include "react/engine/ToposortEngine.h"
2627

2728
/*****************************************/ REACT_BEGIN /*****************************************/
@@ -58,6 +59,9 @@ class ScopedObserver;
5859
template <typename D>
5960
class Reactor;
6061

62+
template <typename D, typename ... TValues>
63+
class SignalPack;
64+
6165
using REACT_IMPL::TurnFlagsT;
6266

6367
//ETurnFlags
@@ -124,13 +128,13 @@ class DomainBase
124128
/// Domain traits
125129
///////////////////////////////////////////////////////////////////////////////////////////////
126130
static const bool uses_node_update_timer =
127-
REACT_IMPL::EnableNodeUpdateTimer<typename Policy::Engine>::value;
131+
REACT_IMPL::NodeUpdateTimerEnabled<typename Policy::Engine>::value;
128132

129-
static const bool uses_concurrent_input =
130-
REACT_IMPL::EnableConcurrentInput<typename Policy::Engine>::value;
133+
static const bool is_concurrent =
134+
REACT_IMPL::IsConcurrentEngine<typename Policy::Engine>::value;
131135

132-
static const bool uses_parallel_updating =
133-
REACT_IMPL::EnableParallelUpdating<typename Policy::Engine>::value;
136+
static const bool is_parallel =
137+
REACT_IMPL::IsParallelEngine<typename Policy::Engine>::value;
134138

135139
///////////////////////////////////////////////////////////////////////////////////////////////
136140
/// Aliases for reactives of this domain
@@ -218,6 +222,130 @@ class DomainBase
218222
#endif //REACT_ENABLE_LOGGING
219223
};
220224

225+
///////////////////////////////////////////////////////////////////////////////////////////////////
226+
/// Continuation
227+
///////////////////////////////////////////////////////////////////////////////////////////////////
228+
template
229+
<
230+
typename TSourceDomain,
231+
typename TTargetDomain
232+
>
233+
class Continuation
234+
{
235+
using NodePtrT = REACT_IMPL::NodeBasePtrT<TSourceDomain>;
236+
237+
public:
238+
using SourceDomainT = TSourceDomain;
239+
using TargetDomainT = TTargetDomain;
240+
241+
Continuation() = default;
242+
Continuation(const Continuation&) = delete;
243+
Continuation& operator=(const Continuation&) = delete;
244+
245+
Continuation(Continuation&& other) :
246+
nodePtr_( std::move(other.nodePtr_) )
247+
{}
248+
249+
explicit Continuation(NodePtrT&& nodePtr) :
250+
nodePtr_( std::move(nodePtr) )
251+
{}
252+
253+
Continuation& operator=(Continuation&& other)
254+
{
255+
nodePtr_ = std::move(other.nodePtr_);
256+
return *this;
257+
}
258+
259+
private:
260+
NodePtrT nodePtr_;
261+
};
262+
263+
///////////////////////////////////////////////////////////////////////////////////////////////////
264+
/// MakeContinuation - Signals
265+
///////////////////////////////////////////////////////////////////////////////////////////////////
266+
template
267+
<
268+
typename D,
269+
typename DOut = D,
270+
typename S,
271+
typename FIn
272+
>
273+
auto MakeContinuation(const Signal<D,S>& trigger, FIn&& func)
274+
-> Continuation<D,DOut>
275+
{
276+
using REACT_IMPL::SignalContinuationNode;
277+
using F = typename std::decay<FIn>::type;
278+
279+
return Continuation<D,DOut>(
280+
std::make_shared<SignalContinuationNode<D,DOut,S,F>>(
281+
trigger.NodePtr(), std::forward<FIn>(func)));
282+
}
283+
284+
///////////////////////////////////////////////////////////////////////////////////////////////////
285+
/// MakeContinuation - Events
286+
///////////////////////////////////////////////////////////////////////////////////////////////////
287+
template
288+
<
289+
typename D,
290+
typename DOut = D,
291+
typename E,
292+
typename FIn
293+
>
294+
auto MakeContinuation(const Events<D,E>& trigger, FIn&& func)
295+
-> Continuation<D,DOut>
296+
{
297+
using REACT_IMPL::EventContinuationNode;
298+
using F = typename std::decay<FIn>::type;
299+
300+
return Continuation<D,DOut>(
301+
std::make_shared<EventContinuationNode<D,DOut,E,F>>(
302+
trigger.NodePtr(), std::forward<FIn>(func)));
303+
}
304+
305+
306+
///////////////////////////////////////////////////////////////////////////////////////////////////
307+
/// MakeContinuation - Synced
308+
///////////////////////////////////////////////////////////////////////////////////////////////////
309+
template
310+
<
311+
typename D,
312+
typename DOut = D,
313+
typename E,
314+
typename FIn,
315+
typename ... TDepValues
316+
>
317+
auto MakeContinuation(const Events<D,E>& trigger,
318+
const SignalPack<D,TDepValues...>& depPack, FIn&& func)
319+
-> Continuation<D,DOut>
320+
{
321+
using REACT_IMPL::SyncedContinuationNode;
322+
using F = typename std::decay<FIn>::type;
323+
324+
struct NodeBuilder_
325+
{
326+
NodeBuilder_(const Events<D,E>& trigger, FIn&& func) :
327+
MyTrigger( trigger ),
328+
MyFunc( std::forward<FIn>(func) )
329+
{}
330+
331+
auto operator()(const Signal<D,TDepValues>& ... deps)
332+
-> Continuation<D,DOut>
333+
{
334+
return Continuation<D,DOut>(
335+
std::make_shared<SyncedContinuationNode<D,DOut,E,F,TDepValues...>>(
336+
MyTrigger.NodePtr(),
337+
std::forward<FIn>(MyFunc), deps.NodePtr() ...));
338+
}
339+
340+
const Events<D,E>& MyTrigger;
341+
FIn MyFunc;
342+
};
343+
344+
return REACT_IMPL::apply(
345+
NodeBuilder_( trigger, std::forward<FIn>(func) ),
346+
depPack.Data);
347+
}
348+
221349
/******************************************/ REACT_END /******************************************/
222350

223351
/***************************************/ REACT_IMPL_BEGIN /**************************************/

0 commit comments

Comments
 (0)