summaryrefslogtreecommitdiff
path: root/core/examples/http_bench_json_ops.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/examples/http_bench_json_ops.rs')
-rw-r--r--core/examples/http_bench_json_ops.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs
index a7db450e4..a61a0ad63 100644
--- a/core/examples/http_bench_json_ops.rs
+++ b/core/examples/http_bench_json_ops.rs
@@ -1,9 +1,10 @@
#[macro_use]
extern crate log;
+use deno_core::error::bad_resource_id;
+use deno_core::error::AnyError;
use deno_core::js_check;
use deno_core::BufVec;
-use deno_core::ErrBox;
use deno_core::JsRuntime;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
@@ -53,7 +54,7 @@ fn op_listen(
state: &mut OpState,
_args: Value,
_bufs: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
debug!("listen");
let addr = "127.0.0.1:4544".parse::<SocketAddr>().unwrap();
let std_listener = std::net::TcpListener::bind(&addr)?;
@@ -66,7 +67,7 @@ fn op_close(
state: &mut OpState,
args: Value,
_buf: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let rid: u32 = args
.get("rid")
.unwrap()
@@ -79,14 +80,14 @@ fn op_close(
.resource_table
.close(rid)
.map(|_| serde_json::json!(()))
- .ok_or_else(ErrBox::bad_resource_id)
+ .ok_or_else(bad_resource_id)
}
fn op_accept(
state: Rc<RefCell<OpState>>,
args: Value,
_bufs: BufVec,
-) -> impl Future<Output = Result<Value, ErrBox>> {
+) -> impl Future<Output = Result<Value, AnyError>> {
let rid: u32 = args
.get("rid")
.unwrap()
@@ -101,7 +102,7 @@ fn op_accept(
let listener = resource_table
.get_mut::<TcpListener>(rid)
- .ok_or_else(ErrBox::bad_resource_id)?;
+ .ok_or_else(bad_resource_id)?;
listener.poll_accept(cx)?.map(|(stream, _addr)| {
let rid = resource_table.add("tcpStream", Box::new(stream));
Ok(serde_json::json!({ "rid": rid }))
@@ -113,7 +114,7 @@ fn op_read(
state: Rc<RefCell<OpState>>,
args: Value,
mut bufs: BufVec,
-) -> impl Future<Output = Result<Value, ErrBox>> {
+) -> impl Future<Output = Result<Value, AnyError>> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let rid: u32 = args
@@ -125,12 +126,12 @@ fn op_read(
.unwrap();
debug!("read rid={}", rid);
- poll_fn(move |cx| -> Poll<Result<Value, ErrBox>> {
+ poll_fn(move |cx| -> Poll<Result<Value, AnyError>> {
let resource_table = &mut state.borrow_mut().resource_table;
let stream = resource_table
.get_mut::<TcpStream>(rid)
- .ok_or_else(ErrBox::bad_resource_id)?;
+ .ok_or_else(bad_resource_id)?;
Pin::new(stream)
.poll_read(cx, &mut bufs[0])?
.map(|nread| Ok(serde_json::json!({ "nread": nread })))
@@ -141,7 +142,7 @@ fn op_write(
state: Rc<RefCell<OpState>>,
args: Value,
bufs: BufVec,
-) -> impl Future<Output = Result<Value, ErrBox>> {
+) -> impl Future<Output = Result<Value, AnyError>> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let rid: u32 = args
@@ -158,7 +159,7 @@ fn op_write(
let stream = resource_table
.get_mut::<TcpStream>(rid)
- .ok_or_else(ErrBox::bad_resource_id)?;
+ .ok_or_else(bad_resource_id)?;
Pin::new(stream)
.poll_write(cx, &bufs[0])?
.map(|nwritten| Ok(serde_json::json!({ "nwritten": nwritten })))