Realtime flows are designed to reach sub-second execution speeds by having all the components always up and running. The most common use case for such type of integration flow is a real-time event processing from external systems. In such cases, the trigger process() function connects to the source of external events and starts receiving data.

The Realtime flow will run indefinitely unless stopped which means the trigger process() function will be called continuously as well. This could be a potential pitfall when implemented carelessly. For example, if your code is of this form:

//import some module which creates listeners
module.exports.process = function processTrigger() {
  const listener = createListener();
  listener.on('event', eventData => { /* some logic here */ });
};

then a listener is created each time the process() function is called. In the case of a Realtime flow, it would mean indefinitely creating numerous listeners all trying to process the same event. To avoid such a repetitive event processing a slight alteration of above code is necessary:

//import some module which creates listeners
let listener;
module.exports.process = function processTrigger() {
  if (!listener) {
    listener = createListener();
    listener.on('event', eventData => { /* some logic here */ });
  }
};

In this case, we will get only one listener created and the trigger will work as expected: single listener for a single event.