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

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

#include <gin_asyncutilities.h>

Inherits juce::AsyncUpdater.

Public Member Functions

 LambdaAsyncUpdater (std::function< void()> func)

Public Attributes

std::function< void()> onAsyncUpdate

Detailed Description

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

LambdaAsyncUpdater provides a more convenient alternative to juce::AsyncUpdater by accepting a lambda or std::function for the async callback. This is useful for safely triggering message-thread operations from other threads without creating a full subclass.

Key Features:

  • Accepts lambda functions or std::function callbacks
  • Thread-safe asynchronous message posting
  • Coalesces multiple trigger calls
  • No need to create subclass for simple async operations
  • Callback can be set at construction

The onAsyncUpdate function is called on the message thread when triggerAsyncUpdate() is called from any thread. Multiple calls are coalesced into a single callback.

Thread Safety:

  • triggerAsyncUpdate() is thread-safe
  • onAsyncUpdate callback runs on message thread only
  • Safe for cross-thread communication

Usage:

// Create with lambda (runs on message thread)
LambdaAsyncUpdater updater([this]() {
// This runs on the message thread
updateUI();
repaint();
});
// Trigger from audio thread or background thread
void audioThreadCallback() {
// Process audio...
updater.triggerAsyncUpdate(); // Safely posts to message thread
}
// Multiple triggers coalesce into one callback
updater.triggerAsyncUpdate();
updater.triggerAsyncUpdate(); // Only one callback will occur
LambdaAsyncUpdater(std::function< void()> func)
Definition gin_asyncutilities.h:117
See also
juce::AsyncUpdater, LambdaTimer, callOnMainThreadBlocking

Constructor & Destructor Documentation

◆ LambdaAsyncUpdater()

LambdaAsyncUpdater::LambdaAsyncUpdater ( std::function< void()> func)

References onAsyncUpdate.

Member Data Documentation

◆ onAsyncUpdate

std::function<void()> LambdaAsyncUpdater::onAsyncUpdate

Referenced by LambdaAsyncUpdater().


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