mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 02:17:45 +00:00
Add const char overload for Component::defer()
This commit is contained in:
parent
58b4e7dab2
commit
7d3a11a735
@ -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
|
||||
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
|
||||
App.scheduler.set_timeout(this, "", timeout, std::move(f));
|
||||
}
|
||||
|
@ -380,6 +380,21 @@ class Component {
|
||||
*/
|
||||
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.
|
||||
void defer(std::function<void()> &&f); // NOLINT
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user