Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion libraries/Ticker/src/Ticker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,28 @@ void Ticker::_static_callback()
}
}

// it is technically allowed to call either schedule or detach
// *during* callback execution. allow both to happen
decltype(_callback) tmp;
std::swap(tmp, _callback);

std::visit([](auto&& callback) {
using T = std::decay_t<decltype(callback)>;
if constexpr (std::is_same_v<T, callback_ptr_t>) {
callback.func(callback.arg);
} else if constexpr (std::is_same_v<T, callback_function_t>) {
callback();
}
}, _callback);
}, tmp);

// ...and move ourselves back only when object is in a valid state
// * ticker was not detached, zeroing timer pointer
// * nothing else replaced callback variant
if ((_timer == nullptr) || !std::holds_alternative<std::monostate>(_callback)) {
return;
}

std::swap(tmp, _callback);

if (_repeat) {
if (_tick) {
Expand Down