Add wait_timeout() method

Not sure I'll end up using this though.
1 files changed, 19 insertions(+), 0 deletions(-)

M src/pond.rs
M src/pond.rs +19 -0
@@ 78,6 78,25 @@ impl<T: Send + 'static> Pond<T> {
         }
     }
 
+    pub fn wait_timeout(&mut self, dur: std::time::Duration) -> Option<TerminatedThread<T>> {
+        let mutex = Arc::clone(&self.mutex);
+        let mut guard = mutex.lock().unwrap();
+        let mut ret = self.reap_threads();
+        while ret.is_none() {
+            let cvar_tuple = self.condv.wait_timeout(guard, dur).unwrap();
+            guard = cvar_tuple.0;
+            ret = self.reap_threads();
+            if ret.is_none() && cvar_tuple.1.timed_out() {
+                return None;
+            }
+        }
+        let thread = ret.unwrap();
+        Some(TerminatedThread {
+            name: thread.name,
+            result: thread.joinhandle.join(),
+        })
+    }
+
     // This is O(n) for N being the number of threads.  HashSet would
     // be O(1) but we assume N is low so this isn't worth it.
     // fn reap_threads<T: Send + 'static>(pond: &mut Pond<T>) -> Option<Thread<T>> {