pub struct OperationCompletion { /* private fields */ }Expand description
The completion signal every operation publishes to when it ends.
This is what lets a caller block until an operation finishes instead of
re-checking it on a timer. A worker marks its id finished here as the very
last thing it does — after the result is stored, the event emitted, and the
final status set — so a waiter woken by it is guaranteed to observe all
three. In particular, is_finished(id) == true implies
LongOperationManager::get_operation_result already has the result (for a
Completed operation), which is what makes an event-free blocking wait
correct.
Obtain one via LongOperationManager::completion_signal and block on it
after releasing any lock guarding the manager — see that method.
Implementations§
Source§impl OperationCompletion
impl OperationCompletion
Sourcepub fn is_finished(&self, id: &str) -> bool
pub fn is_finished(&self, id: &str) -> bool
Has id already reached a final status?
Sourcepub fn wait_for(&self, id: &str, timeout: Option<Duration>) -> bool
pub fn wait_for(&self, id: &str, timeout: Option<Duration>) -> bool
Block until id reaches a final status; true once it has.
There is no lost-wakeup window: the finished-set is inspected while holding the very mutex the condvar is paired with, and a worker must take that same mutex to publish — so an operation that ends between a caller’s check and its wait is already recorded and returns immediately.
timeout bounds one wait, not the whole call, and exists only as a
backstop for a signal that can never arrive (e.g. a worker killed before
publishing). None waits indefinitely.