Dispatcher Task¶
-
namespace Dispatcher¶
Dispatcher task management and control functions.
The dispatcher is a dedicated FreeRTOS task that processes all reactive updates. All Computed nodes and Effect nodes are enqueued to the dispatcher for execution.
- Since
v0.1.0
Note
Must call start() before using any reactive nodes.
Functions¶
-
inline Status start()¶
Start the dispatcher task and queue.
Creates the FreeRTOS dispatcher task and initializes all priority queues. Must be called before using any reactive nodes (Signal / Computed / Effect).
- Since
v0.1.0
Signal<int> counter(0); Computed<int> doubled([]() { return counter.get() * 2; }); void setup() { Serial.begin(115200); if (!Dispatcher::start()) { Serial.println("Failed to start dispatcher!"); while(1) delay(1000); } // Now safe to use reactive nodes counter.set(1); }- Returns:¶
Status::Okon success, error code on failure.
-
inline TaskHandle_t getTaskHandle()¶
Get the task handle of the dispatcher task.
Returns the FreeRTOS task handle for the dispatcher task. Useful for monitoring or integrating with other RTOS features.
- Since
v0.1.0
TaskHandle_t handle = Dispatcher::getTaskHandle(); if (handle != nullptr) { UBaseType_t priority = uxTaskPriorityGet(handle); Serial.printf("Dispatcher priority: %u\n", priority); }- Returns:¶
TaskHandle_tof the dispatcher task,nullptrif not started.
-
inline Status wake(bool from_isr = false)¶
Wake the dispatcher task to process pending work.
Immediately wakes the dispatcher task to process queued reactive updates. Useful when using
queueToSignal()or when manual waking is needed.- Since
v0.1.0
// From normal task context Signal<int> signal(0); QueueHandle_t sensor_queue = xQueueCreate(10, sizeof(int)); Helpers::Utility::queueToSignal(sensor_queue, signal); int value = 123; xQueueSend(sensor_queue, &value, portMAX_DELAY); Dispatcher::wake(); // Wake up dispatcher to process the signal update // From ISR context void IRAM_ATTR onInterrupt() { int data = readSensor(); BaseType_t task_woken = pdFALSE; xQueueSendFromISR(queue, &data, &task_woken); Dispatcher::wake(true); // Wake up dispatcher from ISR }- Parameters:¶
- bool from_isr = false¶
Set to true if calling from an ISR context.
- Returns:¶
Status::Okon success, error code on failure.
-
inline Status pauseReactivity()¶
Pause all reactive updates globally.
Suspends the dispatcher task, preventing all Computed and Effect nodes from executing. Signals can still be modified, but no reactive updates will occur until resumeReactivity() is called.
- Since
v0.1.0
// Batch multiple signal updates without triggering reactive updates Dispatcher::pauseReactivity(); signal1.set(10); // No reactive updates signal2.set(20); // No reactive updates signal3.set(30); // No reactive updates Dispatcher::resumeReactivity(); // All dependents updated nowNote
Signals remain modifiable and track changes while paused. All dependents updates execute when resumeReactivity() is called.
Warning
Pausing reactivity for extended periods may lead to missed updates if the dispatcher event queue becomes full (
RXESP32_DISPATCHER_QUEUE_LENGTH).- Returns:¶
Status::Okon success, error code on failure.
-
inline Status resumeReactivity()¶
Resume reactive updates after pauseReactivity().
Resumes the dispatcher task and wakes it to process any pending updates that occurred while paused.
- Since
v0.1.0
Dispatcher::pauseReactivity(); // ... batch changes ... Dispatcher::resumeReactivity(); // Process all pending updates- Returns:¶
Status::Okon success, error code on failure.
See Also¶
Core - Core Overview