Suggested improvements in runDispathLoopUntil() on OSX

Hi there,

we are extensively using googletests and frequently need to run the message queue to deliver asynchronous callbacks, etc. We have a small function to do this:

void messageManagerFinishTasks()
    bool tasksPending = true;
    MessageManager::callAsync([&tasksPending]() { tasksPending = false; });
    while (tasksPending)
        // dispatch a single message and return

In our tests, we use the ScopeJuceInitialiser_GUI to make sure the message manager exists. Then we can trigger some asynchronous stuff and call messageManagerFinishTasks() to deliver all messages that are left in the queue.

All of this spares us the trouble of doing actual multithreading - it can all happen on one thread.

Now on OSX, this leads to a problem: If we call runDispatchLoopUntil(0) that call will not process a single message because it checks if (msRemaining <= 0) break; BEFORE it actually delivers a message. I know I can just call runDispatchLoopUntil(1) but that can also fail if the thread is interrupted and msRemaining is not 0 anymore by the time the control reaches the check.

I would love to have a function like processUntilEmpty() - or at least be guaranteed that the call to runDispatchLoopUntil(0) will at least process one message by doing the check after the message was delivered (which also makes sense because it makes the timing more accurate).

Could we see something like this in a future update?

PS: Under windows this is not a problem because here the check happens after delivering the message. One more reason to make OSX and Win versions more consistent :slight_smile:

1 Like

I seconds this. It should behave the same on both platforms. I tripped on runDispatchLoopUntil( 0 ) on macOS too.

1 Like