Browse Source

MessageManager: Obey the rule of useful return in callAsync

tags/2021-05-28
reuk ed 5 years ago
parent
commit
c80285463a
2 changed files with 9 additions and 5 deletions
  1. +3
    -3
      modules/juce_events/messages/juce_MessageManager.cpp
  2. +6
    -2
      modules/juce_events/messages/juce_MessageManager.h

+ 3
- 3
modules/juce_events/messages/juce_MessageManager.cpp View File

@@ -184,16 +184,16 @@ void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func
return nullptr;
}
void MessageManager::callAsync (std::function<void()> fn)
bool MessageManager::callAsync (std::function<void()> fn)
{
struct AsyncCallInvoker : public MessageBase
{
AsyncCallInvoker (std::function<void()> f) : callback (std::move (f)) { post(); }
AsyncCallInvoker (std::function<void()> f) : callback (std::move (f)) {}
void messageCallback() override { callback(); }
std::function<void()> callback;
};
new AsyncCallInvoker (std::move (fn));
return (new AsyncCallInvoker (std::move (fn)))->post();
}
//==============================================================================


+ 6
- 2
modules/juce_events/messages/juce_MessageManager.h View File

@@ -94,8 +94,12 @@ public:
#endif
//==============================================================================
/** Asynchronously invokes a function or C++11 lambda on the message thread. */
static void callAsync (std::function<void()> functionToCall);
/** 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.
*/
static bool callAsync (std::function<void()> functionToCall);
/** Calls a function using the message-thread.


Loading…
Cancel
Save