1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added static method Timer::callAfterDelay() to invoke a one-shot lambda function

This commit is contained in:
jules 2017-03-06 15:05:14 +00:00
parent d3bb833f0e
commit 39284e1d0f
2 changed files with 31 additions and 0 deletions

View file

@ -348,3 +348,29 @@ void JUCE_CALLTYPE Timer::callPendingTimersSynchronously()
if (TimerThread::instance != nullptr)
TimerThread::instance->callTimersSynchronously();
}
#if JUCE_COMPILER_SUPPORTS_LAMBDAS
struct LambdaInvoker : private Timer
{
LambdaInvoker (int milliseconds, std::function<void()> f) : function (f)
{
startTimer (milliseconds);
}
void timerCallback() override
{
auto f = function;
delete this;
f();
}
std::function<void()> function;
JUCE_DECLARE_NON_COPYABLE (LambdaInvoker)
};
void JUCE_CALLTYPE Timer::callAfterDelay (int milliseconds, std::function<void()> f)
{
new LambdaInvoker (milliseconds, f);
}
#endif