Add const char overload for Component::defer()

This commit is contained in:
J. Nick Koston 2025-07-04 20:30:04 -05:00
parent 58b4e7dab2
commit 7d3a11a735
No known key found for this signature in database
2 changed files with 18 additions and 0 deletions

View File

@ -248,6 +248,9 @@ bool Component::cancel_defer(const std::string &name) { // NOLINT
void Component::defer(const std::string &name, std::function<void()> &&f) { // NOLINT void Component::defer(const std::string &name, std::function<void()> &&f) { // NOLINT
App.scheduler.set_timeout(this, name, 0, std::move(f)); App.scheduler.set_timeout(this, name, 0, std::move(f));
} }
void Component::defer(const char *name, std::function<void()> &&f) { // NOLINT
App.scheduler.set_timeout(this, name, 0, std::move(f));
}
void Component::set_timeout(uint32_t timeout, std::function<void()> &&f) { // NOLINT void Component::set_timeout(uint32_t timeout, std::function<void()> &&f) { // NOLINT
App.scheduler.set_timeout(this, "", timeout, std::move(f)); App.scheduler.set_timeout(this, "", timeout, std::move(f));
} }

View File

@ -380,6 +380,21 @@ class Component {
*/ */
void defer(const std::string &name, std::function<void()> &&f); // NOLINT void defer(const std::string &name, std::function<void()> &&f); // NOLINT
/** Defer a callback to the next loop() call with a const char* name.
*
* IMPORTANT: The provided name pointer must remain valid for the lifetime of the deferred task.
* This means the name should be:
* - A string literal (e.g., "update")
* - A static const char* variable
* - A pointer with lifetime >= the deferred execution
*
* For dynamic strings, use the std::string overload instead.
*
* @param name The name of the defer function (must have static lifetime)
* @param f The callback
*/
void defer(const char *name, std::function<void()> &&f); // NOLINT
/// Defer a callback to the next loop() call. /// Defer a callback to the next loop() call.
void defer(std::function<void()> &&f); // NOLINT void defer(std::function<void()> &&f); // NOLINT