summaryrefslogtreecommitdiff
path: root/cli/worker.rs
diff options
context:
space:
mode:
authorYiyu Lin <linyiyu1992@gmail.com>2020-05-17 12:50:38 +0800
committerGitHub <noreply@github.com>2020-05-17 06:50:38 +0200
commitc4fe58d8df51e8f07142803ec0522f862fd30a3f (patch)
treecd10811ffd740271cb0e510171198cf69221b570 /cli/worker.rs
parentf12dffca9fbe0effb1a862ffd2854196d96d4af1 (diff)
Return error if more than one listener calls `WorkerHandle::get_event()` (#5461)
Diffstat (limited to 'cli/worker.rs')
-rw-r--r--cli/worker.rs10
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)
}
}