batchedEffect Helper

Basic Overload

template<typename ...Sources>
BatchedEffect<Sources...> RxESP32::Helpers::Utility::batchedEffect(typename Effect<1>::EffectFunction action_fn, uint32_t batch_window_ms, Sources&... sources)

Create a BatchedEffect that groups rapid source updates into single action execution.

Factory function to create a BatchedEffect with default options.

Since

v0.1.0

Signal<int> sensor1(0);
Signal<int> sensor2(0);

int times_effect_run = 0;

// Effect that is batched with 100ms delay
auto effect = batchedEffect([]() {
  times_effect_run++;
  Serial.println("Batched effect executed");
  return nullptr;
}, 100, sensor1, sensor2);

// Rapid updates to sensors
sensor1.set(10);
sensor2.set(20);
sensor1.set(30);
sensor2.set(40);
// Effect runs only once after 100ms

Note

Internally uses debounce helper.

Template Parameters:
typename ...Sources

Types of sources.

Parameters:
typename Effect<1>::EffectFunction action_fn

Action function to execute after batch window.

uint32_t batch_window_ms

Time window in milliseconds to batch updates.

Sources&... sources

Sources to monitor.

Returns:

BatchedEffect managing the batched action execution.

With Options

template<typename ...Sources>
BatchedEffect<Sources...> RxESP32::Helpers::Utility::batchedEffect(typename Effect<1>::EffectFunction action_fn, uint32_t batch_window_ms, const typename Effect<1>::Options &options, Sources&... sources)

Create a BatchedEffect that groups rapid source updates into single action execution.

Factory function to create a BatchedEffect with custom options.

Since

v0.1.0

Signal<int> sensor1(0);
Signal<int> sensor2(0);

int times_effect_run = 0;

// Effect that is batched with 100ms delay and custom options
auto effect = batchedEffect([]() {
  times_effect_run++;
  Serial.println("Batched effect executed");
  return nullptr;
}, 100, {.name = "BatchedEffect"}, sensor1, sensor2);

// Rapid updates to sensors
sensor1.set(10);
sensor2.set(20);
sensor1.set(30);
sensor2.set(40);
// Effect runs only once after 100ms

Note

Internally uses debounce helper.

Template Parameters:
typename ...Sources

Types of sources.

Parameters:
typename Effect<1>::EffectFunction action_fn

Action function to execute after batch window.

uint32_t batch_window_ms

Time window in milliseconds to batch updates.

const typename Effect<1>::Options &options

Effect options for the executor.

Sources&... sources

Sources to monitor.

Returns:

BatchedEffect managing the batched action execution.

See Also