Workflow Design Guidelines
This section offers guidelines and design patterns to consider when developing workflows for any reactive program.
Workflow Organization
use GroupWorkflow
nodes to separate independent functionality (e.g. acquisition, visualization and processing).
branching without merging.
Subject Declaration
Using subjects is one of the most important techniques for improving readability and managing the complexity of large workflows. Subjects make it possible to reduce the number of branches in the workflow and also allow abstraction over data sources and sinks so that you can easily replace different components. Finally, subjects are fundamental for managing and storing data inside nested operators.
prefer using subjects over branches when sharing sequences across independent sections of the workflow.
use a BehaviorSubject
to share global state which can be accessed by multiple consumers and modified by multiple producers.
using MulticastSubject
on variables which are not declared as BehaviorSubject
. This will prevent accidental termination of the subject sequence if a producer terminates prematurely.
using source subjects when sharing a sequence with one consumer where data is generated by zero or more producers.
moving all subject declarations to the top of the workflow. This will make sure that subject initialization order is easily readable from top to bottom.
Nested Operators
Several reactive operators require specification of a nested workflow, e.g. SelectMany
or CreateObservable
. The operator itself will control when the nested workflow is initialized and subscribed to. If it is possible for a nested workflow to be executed multiple times, potentially in parallel, we call the operator reentrant. Some care is necessary to understand how to manage shared state and properties inside a reentrant nested operator.
use an AsyncSubject
to share workflow input data inside a nested operator.
using PropertyMapping
nodes inside reentrant nested operators.
Property Initialization
branch a source sequence to share the same value across different PropertyMapping
nodes. This can introduce a race condition for operators that use property values at subscribe time.
Alternatively, you can either share the value using a subject, or branch after the PropertyMapping
node (if both the value to share and the name of the property in each node are identical).