Rust: CondVar wait functions accepting a closure

Created on 2 Feb 2018  路  6Comments  路  Source: rust-lang/rust

Pretty common for conditional variable classes to provide wait variants that accept a closure that returns a boolean indicating whether or not the condition has been satisfied. This would be a pretty nice ergonomic improvement to using CondVar. Something like cvar.wait_until(lock, || { some condition }). Even more useful would be a wait_timeout_until which would avoid the need to keep track of elapsed time if the condition variable might get notified several times before the condition is met.

A-concurrency B-unstable C-tracking-issue T-libs

Most helpful comment

Is anything preventing stabilization of this?

All 6 comments

Generally, for small features, we just take PRs, and for big ones, issues. I'm not sure if @rust-lang/libs considers this a small or large feature.

This seems small enough for a direct PR, yes.

Will prepare it. Still a little new to rust. Would the callback be Fn or FnMut?

FnMut - closures should generally be as flexible as possible.

Is anything preventing stabilization of this?

@rust-lang/libs can I nominate this for stabilization? We've been using these in the code base at my job for a while, and we'd love to move to stable Rust soon without needing to shim these out.

Was this page helpful?
0 / 5 - 0 ratings