I can of course wrap this up into a free function my end but it seems a reasonable addition and easy enough to add, diff below.
diff --git a/modules/juce_core/threads/juce_WaitableEvent.cpp b/modules/juce_core/threads/juce_WaitableEvent.cpp
index 8b01c4db2..223fbe248 100644
--- a/modules/juce_core/threads/juce_WaitableEvent.cpp
+++ b/modules/juce_core/threads/juce_WaitableEvent.cpp
@@ -28,7 +28,7 @@ WaitableEvent::WaitableEvent (bool manualReset) noexcept
{
}
-bool WaitableEvent::wait (int timeOutMilliseconds) const
+bool WaitableEvent::wait (int64 timeOutMilliseconds) const
{
std::unique_lock<std::mutex> lock (mutex);
@@ -52,6 +52,14 @@ bool WaitableEvent::wait (int timeOutMilliseconds) const
reset();
return true;
+}
+
+bool WaitableEvent::waitUntil (const juce::Time& timeToWaitUntil) const
+{
+ auto timeOutMilliseconds = (timeToWaitUntil - juce::Time::getCurrentTime()).inMilliseconds();
+ timeOutMilliseconds = juce::jmax (0ll, timeOutMilliseconds);
+
+ return wait (timeOutMilliseconds);
}
void WaitableEvent::signal() const
diff --git a/modules/juce_core/threads/juce_WaitableEvent.h b/modules/juce_core/threads/juce_WaitableEvent.h
index 3e31a9772..9868501f9 100644
--- a/modules/juce_core/threads/juce_WaitableEvent.h
+++ b/modules/juce_core/threads/juce_WaitableEvent.h
@@ -58,10 +58,30 @@ public:
@param timeOutMilliseconds the maximum time to wait, in milliseconds. A negative
value will cause it to wait forever.
- @returns true if the object has been signalled, false if the timeout expires first.
- @see signal, reset
+ @returns true if the object has been signalled, false if the timeout expires first.
+
+ @see waitUntil, signal, reset
*/
- bool wait (int timeOutMilliseconds = -1) const;
+ bool wait (int64 timeOutMilliseconds = -1) const;
+
+ /** Suspends the calling thread until the event has been signalled.
+
+ This will wait until the object's signal() method is called by another
+ thread, or the specified time is reached.
+
+ After the event has been signalled, this method will return true and if
+ manualReset was set to false in the WaitableEvent's constructor, then
+ the event will be reset.
+
+ @param timeToWaitUntil the time to wait until. A time in the past will
+ return as if called with the current time.
+
+ @returns true if the object has been signalled, false if the specified
+ time is reached first.
+
+ @see wait, signal, reset
+ */
+ bool waitUntil (const juce::Time& timeToWaitUntil) const;
/** Wakes up any threads that are currently waiting on this object.