Event Receptions

Events are useful mechanisms to transfer data and control from asynchronous events back to the Reactive Blocks runtime. They are typically used for blocking or CPU intensive operations that need to run in separate threads so that they comply with the Run to completion rule described here.

Note that usage is not limited from threads, but may also be used within a block.

  • Event receptions are added within a block from the context menu

  • Events may or may not contain data payload. Defining the datatype is done from within the Event symbol context menu (right click on event reception) and select or remove Data Type
  • Note the Repeat flag. It must be enabled if the event may happen several times. If not enabled, the event can be received only once. In our example the event needs to be received only once and therefore the flag is not enabled.

Generating events

  • In your block an event reception looks like this

  • Note the edge from getPrime to the event reception, this is what tells Reactive Blocks that an event name PRIME may be expected.

  • The PRIME event is generated from within a thread in the GetPrime class using sendToBlock. Note that the getPrime method returns immediately giving control back to the Reactive Blocks runtime after having started the thread.