summaryrefslogtreecommitdiff
path: root/ext/broadcast_channel/lib.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-08-15 13:29:19 +0200
committerGitHub <noreply@github.com>2021-08-15 13:29:19 +0200
commit2ca454b402d48c1808f8233c5adedc11b714c63c (patch)
tree592f9e877e9b0ae92be80383ab723cc290e4b01e /ext/broadcast_channel/lib.rs
parent18ff6bb053d600c277613628a256fe5fdd4dda67 (diff)
refactor(ops): return BadResource errors in ResourceTable calls (#11710)
* refactor(ops): return BadResource errors in ResourceTable calls Instead of relying on callers to map Options to Results via `.ok_or_else(bad_resource_id)` at over 176 different call sites ...
Diffstat (limited to 'ext/broadcast_channel/lib.rs')
-rw-r--r--ext/broadcast_channel/lib.rs18
1 files changed, 3 insertions, 15 deletions
diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs
index 3f88db162..de6c56667 100644
--- a/ext/broadcast_channel/lib.rs
+++ b/ext/broadcast_channel/lib.rs
@@ -5,7 +5,6 @@ mod in_memory_broadcast_channel;
pub use in_memory_broadcast_channel::InMemoryBroadcastChannel;
use async_trait::async_trait;
-use deno_core::error::bad_resource_id;
use deno_core::error::AnyError;
use deno_core::include_js_files;
use deno_core::op_async;
@@ -68,10 +67,7 @@ pub fn op_broadcast_unsubscribe<BC: BroadcastChannel + 'static>(
rid: ResourceId,
_buf: (),
) -> Result<(), AnyError> {
- let resource = state
- .resource_table
- .get::<BC::Resource>(rid)
- .ok_or_else(bad_resource_id)?;
+ let resource = state.resource_table.get::<BC::Resource>(rid)?;
let bc = state.borrow::<BC>();
bc.unsubscribe(&resource)
}
@@ -81,11 +77,7 @@ pub async fn op_broadcast_send<BC: BroadcastChannel + 'static>(
(rid, name): (ResourceId, String),
buf: ZeroCopyBuf,
) -> Result<(), AnyError> {
- let resource = state
- .borrow()
- .resource_table
- .get::<BC::Resource>(rid)
- .ok_or_else(bad_resource_id)?;
+ let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
let bc = state.borrow().borrow::<BC>().clone();
bc.send(&resource, name, buf.to_vec()).await
}
@@ -95,11 +87,7 @@ pub async fn op_broadcast_recv<BC: BroadcastChannel + 'static>(
rid: ResourceId,
_buf: (),
) -> Result<Option<Message>, AnyError> {
- let resource = state
- .borrow()
- .resource_table
- .get::<BC::Resource>(rid)
- .ok_or_else(bad_resource_id)?;
+ let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
let bc = state.borrow().borrow::<BC>().clone();
bc.recv(&resource).await
}