[web_server_idf] Preserve on_connect_ ordering and document main-loop context

Pre-refactor, on_connect_ ran after the ctor had already sent the
initial ping/config/sorting_groups. Call start_session_main_loop_()
before on_connect_ so the callback still observes a primed session.

Also document at onConnect() that the callback now runs on the main
loop instead of the httpd task.
This commit is contained in:
J. Nick Koston
2026-04-24 03:10:17 -05:00
parent 121b4d6916
commit 3507d567cc
2 changed files with 5 additions and 1 deletions
@@ -532,10 +532,12 @@ void AsyncEventSource::adopt_pending_sessions_main_loop_() {
continue;
}
this->sessions_.push_back(rsp);
// Prime first so on_connect_ observes a session that has already sent its
// initial ping/config/sorting_groups, matching the pre-refactor ordering.
rsp->start_session_main_loop_();
if (this->on_connect_) {
this->on_connect_(rsp);
}
rsp->start_session_main_loop_();
}
}
@@ -339,6 +339,8 @@ class AsyncEventSource : public AsyncWebHandler {
// NOLINTNEXTLINE(readability-identifier-naming)
void handleRequest(AsyncWebServerRequest *request) override;
// NOLINTNEXTLINE(readability-identifier-naming)
// Callback runs on the main loop (not the httpd task) after the session's
// initial ping/config/sorting_groups have been sent.
void onConnect(connect_handler_t &&cb) { this->on_connect_ = std::move(cb); }
void try_send_nodefer(const char *message, const char *event = nullptr, uint32_t id = 0, uint32_t reconnect = 0);