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.

Processing Events

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.

vl libraries reactive refreshEvery30secInBackground.PNG
Refresh web data every 30 seconds in the background and pass the result on to the mainloop.

Switching or merging event sources

vl libraries reactive switchingAndMerging.PNG
Switching or merging midi events.


There are also filtering options with OfType or Where:

vl libraries reactive onlyGetTouchDown.PNG
Only get TouchDown events from a combined event stream.

Other nodes include

  • Skip,

  • Delay,

  • Delay (Selector),

  • Scan,

  • Switch, …​

Receiving Events

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:

vl libraries reactive 3waysToGetEventValuesToMainloop.PNG
Three ways to get event values to the mainloop.

Creating Events

It’s also easy to generate event sources of your own:

vl libraries reactive waysToCreateObservableSources.PNG
Different ways to create observable event sources.
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!

results matching ""

    No results matching ""