Gin
Loading...
Searching...
No Matches
LambdaTimer Class Reference

Timer that calls a std::function callback instead of requiring virtual override. More...

#include <gin_asyncutilities.h>

Inherits juce::Timer.

Public Member Functions

 LambdaTimer (std::function< void()> func=nullptr)

Public Attributes

std::function< void()> onTimer

Detailed Description

Timer that calls a std::function callback instead of requiring virtual override.

LambdaTimer provides a more convenient alternative to juce::Timer by accepting a lambda or std::function for the timer callback. This eliminates the need to create a subclass or override timerCallback() for simple timer operations.

Key Features:

  • Accepts lambda functions or std::function callbacks
  • Same timing capabilities as juce::Timer
  • No need to create subclass for simple timers
  • Callback can be changed at runtime
  • Cleaner code for inline timer operations

The onTimer function is called at the specified interval. All juce::Timer methods are available (startTimer, stopTimer, isTimerRunning, etc.).

Usage:

// Create with lambda
LambdaTimer timer([this]() {
updateDisplay();
});
timer.startTimer(100); // Call every 100ms
// Create and assign later
timer.onTimer = [this]() {
checkForUpdates();
};
timer.startTimer(1000); // Call every second
// Stop timer
timer.stopTimer();
Timer that calls a std::function callback instead of requiring virtual override.
Definition gin_asyncutilities.h:53
std::function< void()> onTimer
Definition gin_asyncutilities.h:57
LambdaTimer(std::function< void()> func=nullptr)
Definition gin_asyncutilities.h:55
See also
juce::Timer, LambdaAsyncUpdater

Constructor & Destructor Documentation

◆ LambdaTimer()

LambdaTimer::LambdaTimer ( std::function< void()> func = nullptr)

References onTimer.

Member Data Documentation

◆ onTimer

std::function<void()> LambdaTimer::onTimer

Referenced by LambdaTimer().


The documentation for this class was generated from the following file: