# Event Simulation

This module is designed to simulate various events to test and validate workflows. By generating events, you can ensure that your workflow handles different scenarios and edge cases effectively, providing a robust and reliable system. It is also helpful as a placeholder in your workflow, if you haven't completed your app yet.

The different available functions offer ways to respond to specific events. To learn more about event handlers, see [Callbacks](https://docs.heisenware.com/app-builder/build-backend/functions-library/utilities/broken-reference).

To access the events simulator, unfold `Simulation` > `Events` in the functionality panel.

## Instance management

### Create an instance

Simply drag the `create` function onto the board, insert a unique name for your instance and trigger the function.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2F14oqll9aWDQQliiJr8Ki%2Fcreate_instance.png?alt=media&#x26;token=cab93cf5-5988-4071-885b-743f3e83743b" alt=""><figcaption><p>Creating an events simulator instance</p></figcaption></figure>

### Delete an instance

Simply drag the `delete` function onto the board and insert the name of the instance you want to delete.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2F44h2d0jkzMnXT5B6FuFm%2Fdelete_instance.png?alt=media&#x26;token=c4b42a76-4b4c-4be6-8d95-f1d7e0ed9bdd" alt=""><figcaption><p>Deleting an events simulator instance</p></figcaption></figure>

## Instance functions

### Reacting to a manually triggered event

The `onManualTrigger` function catches a manual trigger of the `triggerManually` function in the same instance and outputs the payload, which is a UNIX timestamp in this case. To try this, simply drag both functions onto the logic board and trigger the `triggerManually` function to generate the necessary event.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FHRlM7zQGytbltDUJPfQH%2Fimage.png?alt=media&#x26;token=4f75a4b2-a2a7-4f10-96d0-bde38a98ed18" alt=""><figcaption><p>After triggering the second function, the first outputs the timestamp</p></figcaption></figure>

### Reacting to an automatically triggered event

The `onAutoTrigger` reacts to the automatic trigger set up by startAutoTrigger and displays the UNIX timestamp payload. You can set an interval after which the event should repeat in milliseconds in the `interval` input box. You might need to trigger `onAutoTrigger` once for it to start reacting to the automatically generated events after triggering `startAutoTrigger`.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Fnmb2sVDVQOwRCHcFNcWw%2Fimage.png?alt=media&#x26;token=0a12bf53-61a7-4a03-bb09-d95b595e054b" alt=""><figcaption><p>Reacting to periodically generated events</p></figcaption></figure>

You can stop the automatic trigger with the `stopAutoTrigger` function.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FEzGu2jARD8GqfUjeYlq1%2Fstopautotrigger.png?alt=media&#x26;token=6672823d-6006-4ef1-85f0-c39317716d15" alt=""><figcaption><p>Stopping the generation of events</p></figcaption></figure>

### Reacting with a callback to output of same function&#x20;

The `triggerCallback` function reacts to an event triggered by itself. After triggering the function, there will be a delay, as set by the `timeout` input box in milliseconds. It will NOT react to the output of the callback to avoid an infinite loop.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FveNeCVrYTMObAez6gjYD%2FtriggerCallback.png?alt=media&#x26;token=0203ba1d-7358-4e75-86ab-516b6bd29c3a" alt=""><figcaption><p>Callback output as reaction to function generated event</p></figcaption></figure>
