Merge remote-tracking branch 'upstream/scheduler_wake_when_defer_pending' into integration

This commit is contained in:
J. Nick Koston
2026-04-24 03:28:04 -05:00
+8
View File
@@ -417,6 +417,14 @@ optional<uint32_t> HOT Scheduler::next_schedule_in(uint32_t now) {
// It performs cleanup and accesses items_[0] without holding a lock, which is only
// safe when called from the main thread. Other threads must not call this method.
#ifndef ESPHOME_THREAD_SINGLE
// defer() items live in a separate queue that is drained at the top of every
// loop tick via process_defer_queue_(). If any are pending, the next loop
// iteration has work to do right now -- don't let the caller sleep.
if (!this->defer_empty_())
return 0;
#endif
// If no items, return empty optional
if (!this->cleanup_())
return {};