diff options
Diffstat (limited to 'cli/worker.rs')
-rw-r--r-- | cli/worker.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/cli/worker.rs b/cli/worker.rs index d52d96594..b66c1cb06 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -51,11 +51,11 @@ impl WorkerHandle { sender.try_send(buf).map_err(ErrBox::from) } - // TODO: should use `try_lock` and return error if - // more than one listener tries to get event - pub async fn get_event(&self) -> Option<WorkerEvent> { - let mut receiver = self.receiver.lock().await; - receiver.next().await + /// Get the event with lock. + /// Return error if more than one listener tries to get event + pub async fn get_event(&self) -> Result<Option<WorkerEvent>, ErrBox> { + let mut receiver = self.receiver.try_lock()?; + Ok(receiver.next().await) } } |