mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
Return error if more than one listener calls WorkerHandle::get_event()
(#5461)
This commit is contained in:
parent
f12dffca9f
commit
c4fe58d8df
4 changed files with 11 additions and 11 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue