The Reactive category gives you tools to handle asynchronous events, background calculations and even enables you to build your own mainloop that runs on a different CPU core.
The go to node for handling events is the ForEach Region in the category Reactive. This region allows you to place any node inside and can also remember any data between two events. There is also one with version Keep that can filter out events using a boolean output. This region is very similar to the ForEach region for spreads, only that its input and output is event values in time instead of slices of a spread.
Refresh web data every 30 seconds in the background and pass the result on to the mainloop Switching or merging midi eventsThere are also filtering options with OfType or Where:
Only get TouchDown events from a combined event streamOther nodes include
- Skip,
- Delay,
- Delay (Selector),
- Scan,
- Switch, ...
If you want to leave the observable world and pass event values to the mainloop use one of the 3 nodes
- HoldLatest: Returns always the latest value
- Sampler: Returns all event values since the last frame, can be empty
- S+H: Same as Sampler but returns the same values until the next event occurs
which all behave a little bit different. Depends on what you need:
Three ways to get event values to the mainloopIt's also easy to generate event sources of your own:
Different ways to create observable event sourcesNote
Only send values of type Record as event data because they are thread safe. If you send values of any Class type be sure that you know exactly what you are doing!