1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

Added a handy static method MessageManager::callAsync() which can asynchronously invoke a lambda on the message thread.

This commit is contained in:
jules 2014-10-07 17:15:19 +01:00
parent 743f04dc01
commit df3e039bf9
2 changed files with 21 additions and 0 deletions

View file

@ -131,6 +131,22 @@ void MessageManager::stopDispatchLoop()
#endif
//==============================================================================
struct AsyncFunction : private MessageManager::MessageBase
{
AsyncFunction (std::function<void(void)> f) : fn (f) { post(); }
private:
std::function<void(void)> fn;
void messageCallback() override { fn(); }
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AsyncFunction)
};
void MessageManager::callAsync (std::function<void(void)> f)
{
new AsyncFunction (f);
}
class AsyncFunctionCallback : public MessageManager::MessageBase
{
public:

View file

@ -91,6 +91,11 @@ public:
#endif
//==============================================================================
/** Asynchronously invokes a function or C++11 lambda on the message thread.
Internally this uses the CallbackMessage class to invoke the callback.
*/
static void callAsync (std::function<void(void)>);
/** Calls a function using the message-thread.
This can be used by any thread to cause this function to be called-back