11namespace tracktion {
inline namespace engine
25 function = std::move (f);
37 function = std::move (f);
41 void handleAsyncUpdate()
override
68 functions[functionID] = {
false, f };
74 auto found = functions.
find (functionID);
76 if (found != functions.
end())
78 found->second.first =
true;
99 void handleAsyncUpdate()
override
101 auto compareAndReset = [] (
bool& flag) ->
bool
110 for (
auto&& f : functions)
111 if (compareAndReset (f.second.first))
126 callback = std::move (newCallback);
131 callback = std::move (newCallback);
134 template<
typename DurationType>
137 juce::Timer::startTimer (
static_cast<int> (std::chrono::duration_cast<std::chrono::milliseconds> (interval).count()));
142 void timerCallback()
override
170 if (juce::MessageManager::getInstance()->isThisTheMessageThread())
183 if (job->shouldExit())
185 hasBeenCancelled =
true;
192 if (
auto thread = juce::Thread::getCurrentThread())
194 while (! (thread->threadShouldExit() ||
hasFinished()))
197 if (thread->threadShouldExit())
199 hasBeenCancelled =
true;
206 TRACKTION_LOG_ERROR (
"Rogue call to triggerAndWaitForCallback()");
213 TRACKTION_LOG_ERROR (
"triggerAndWaitForCallback() unable to complete");
217 virtual void performAction() = 0;
223 void handleAsyncUpdate()
override
226 TRACKTION_ASSERT_MESSAGE_THREAD
228 if (hasBeenCancelled)
246 void performAction()
override { fn(); }
254 bf.triggerAndWaitForCallback();
255 return bf.hasFinished();
void handleUpdateNowIfNeeded()
void triggerAsyncUpdate()
void cancelPendingUpdate() noexcept
static ThreadPoolJob * getCurrentThreadPoolJob()
void startTimer(int intervalInMilliseconds) noexcept
bool wait(double timeOutMilliseconds=-1.0) const
Calls a function on the message thread checking a calling thread for an exit signal.
void triggerAndWaitForCallback()
Triggers the callback to happen on the message thread and blocks until it has returned or the thread ...
bool hasFinished() const noexcept
Returns true if the callback has completed.
Asyncronously call a function.
void setFunction(std::function< void()> f)
Sets the function to call.
AsyncCaller(std::function< void()> f)
Creates an AsyncCaller with a given callback function.
~AsyncCaller() override
Destructor.
AsyncCaller()=default
Creates an empty AsyncCaller.
Holds a list of function objects and enables you to call them asyncronously.
void updateAsync(int functionID)
Triggers an asyncronous call to one of the functions.
void handleUpdateNowIfNeeded()
If an update has been triggered and is pending, this will invoke it synchronously.
AsyncFunctionCaller()=default
Creates an empty AsyncFunctionCaller.
void addFunction(int functionID, const std::function< void()> &f)
Adds a function and associates a functionID with it.
~AsyncFunctionCaller() override
Destructor.
#define CRASH_TRACER
This macro adds the current location to a stack which gets logged if a crash happens.