diff --git a/main/espFeatures/freeRTOSEventQueue.h b/main/espFeatures/freeRTOSEventQueue.h index 800791e..35f39fc 100644 --- a/main/espFeatures/freeRTOSEventQueue.h +++ b/main/espFeatures/freeRTOSEventQueue.h @@ -126,6 +126,15 @@ class FreeRTOSEventQueueFeature : public Next { } } + void drain() { + while(true) { + Event e; + if(xQueueReceive(_eventQueue, &e, 0) == pdFALSE) { + break; + } + } + } + void _scheduleImpl(auto&&... args) { Event e(std::forward(args)...); auto res = xQueueSend(_eventQueue, &e, portMAX_DELAY); @@ -217,8 +226,7 @@ class FreeRTOSEventQueueFeature : public Next { } ~FreeRTOSEventQueueFeature() { - notifyEventLoop(); - while (dequeue(false)) {} + drain(); vQueueDelete(_eventQueue); } };