| @@ -348,3 +348,29 @@ void JUCE_CALLTYPE Timer::callPendingTimersSynchronously() | |||||
| if (TimerThread::instance != nullptr) | if (TimerThread::instance != nullptr) | ||||
| TimerThread::instance->callTimersSynchronously(); | 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 | |||||
| @@ -121,6 +121,11 @@ public: | |||||
| */ | */ | ||||
| int getTimerInterval() const noexcept { return timerPeriodMs; } | int getTimerInterval() const noexcept { return timerPeriodMs; } | ||||
| //============================================================================== | |||||
| #if JUCE_COMPILER_SUPPORTS_LAMBDAS | |||||
| /** Invokes a lambda after a given number of milliseconds. */ | |||||
| static void JUCE_CALLTYPE callAfterDelay (int milliseconds, std::function<void()> functionToCall); | |||||
| #endif | |||||
| //============================================================================== | //============================================================================== | ||||
| /** For internal use only: invokes any timers that need callbacks. | /** For internal use only: invokes any timers that need callbacks. | ||||