Amanieu / parking_lot

Compact and efficient synchronization primitives for Rust. Also provides an API for creating custom synchronization primitives.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Condvar::wait_while and Condvar::wait_timeout_while convenience methods

bryanhitc opened this issue · comments

The standard library has Convar::wait_while and Convar::wait_timeout_while methods that take a condition: impl Fn(&mut T) -> bool. These convenience methods are great since the following pattern is relatively common:

while condition(&mut *lock_guard) {
  cv.wait(lock_guard);
}

// condition is now false

I think it'd be great to have these convenience methods built-in, but I can also see an argument being made for not wanting to clutter the public API. Thoughts?

I'm more than happy to submit the PR if this functionality is desired.

Sure! I'd be happy to accept a PR for this.