diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-08-15 13:29:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-15 13:29:19 +0200 |
commit | 2ca454b402d48c1808f8233c5adedc11b714c63c (patch) | |
tree | 592f9e877e9b0ae92be80383ab723cc290e4b01e /core/examples/http_bench_json_ops.rs | |
parent | 18ff6bb053d600c277613628a256fe5fdd4dda67 (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 'core/examples/http_bench_json_ops.rs')
-rw-r--r-- | core/examples/http_bench_json_ops.rs | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index 82eb18d6b..d273c2c88 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -1,5 +1,4 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use deno_core::error::bad_resource_id; use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::AsyncRefCell; @@ -140,11 +139,7 @@ fn op_close( _: (), ) -> Result<(), AnyError> { log::debug!("close rid={}", rid); - state - .resource_table - .close(rid) - .map(|_| ()) - .ok_or_else(bad_resource_id) + state.resource_table.close(rid).map(|_| ()) } async fn op_accept( @@ -154,11 +149,7 @@ async fn op_accept( ) -> Result<ResourceId, AnyError> { log::debug!("accept rid={}", rid); - let listener = state - .borrow() - .resource_table - .get::<TcpListener>(rid) - .ok_or_else(bad_resource_id)?; + let listener = state.borrow().resource_table.get::<TcpListener>(rid)?; let stream = listener.accept().await?; let rid = state.borrow_mut().resource_table.add(stream); Ok(rid) @@ -172,11 +163,7 @@ async fn op_read( let mut buf = buf.ok_or_else(null_opbuf)?; log::debug!("read rid={}", rid); - let stream = state - .borrow() - .resource_table - .get::<TcpStream>(rid) - .ok_or_else(bad_resource_id)?; + let stream = state.borrow().resource_table.get::<TcpStream>(rid)?; let nread = stream.read(&mut buf).await?; Ok(nread) } @@ -189,11 +176,7 @@ async fn op_write( let buf = buf.ok_or_else(null_opbuf)?; log::debug!("write rid={}", rid); - let stream = state - .borrow() - .resource_table - .get::<TcpStream>(rid) - .ok_or_else(bad_resource_id)?; + let stream = state.borrow().resource_table.get::<TcpStream>(rid)?; let nwritten = stream.write(&buf).await?; Ok(nwritten) } |