mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
MessageManager: Update callAsync to take an arbitrary callable instead of a function
This commit is contained in:
parent
19edd53842
commit
29cf6ecf04
2 changed files with 17 additions and 15 deletions
|
|
@ -204,18 +204,6 @@ void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool MessageManager::callAsync (std::function<void()> fn)
|
||||
{
|
||||
struct AsyncCallInvoker final : public MessageBase
|
||||
{
|
||||
AsyncCallInvoker (std::function<void()> f) : callback (std::move (f)) {}
|
||||
void messageCallback() override { callback(); }
|
||||
std::function<void()> callback;
|
||||
};
|
||||
|
||||
return (new AsyncCallInvoker (std::move (fn)))->post();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void MessageManager::deliverBroadcastMessage (const String& value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -103,10 +103,24 @@ public:
|
|||
//==============================================================================
|
||||
/** Asynchronously invokes a function or C++11 lambda on the message thread.
|
||||
|
||||
@returns true if the message was successfully posted to the message queue,
|
||||
or false otherwise.
|
||||
@param function the function to call, which should have no arguments
|
||||
@returns true if the message was successfully posted to the message queue,
|
||||
or false otherwise.
|
||||
*/
|
||||
static bool callAsync (std::function<void()> functionToCall);
|
||||
template <typename Function>
|
||||
static bool callAsync (Function&& function)
|
||||
{
|
||||
using NonRef = std::remove_cv_t<std::remove_reference_t<Function>>;
|
||||
|
||||
struct AsyncCallInvoker final : public MessageBase
|
||||
{
|
||||
explicit AsyncCallInvoker (NonRef f) : fn (std::move (f)) {}
|
||||
void messageCallback() override { fn(); }
|
||||
NonRef fn;
|
||||
};
|
||||
|
||||
return (new AsyncCallInvoker { std::move (function) })->post();
|
||||
}
|
||||
|
||||
/** Calls a function using the message-thread.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue