diff options
Diffstat (limited to 'core/examples/http_bench_json_ops.rs')
-rw-r--r-- | core/examples/http_bench_json_ops.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index 9e60df4a4..3f608eeae 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -1,5 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::Error; +use deno_core::op; use deno_core::AsyncRefCell; use deno_core::AsyncResult; use deno_core::CancelHandle; @@ -17,6 +18,11 @@ use std::rc::Rc; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; +// This is a hack to make the `#[op]` macro work with +// deno_core examples. +// You can remove this: +use deno_core::*; + struct Logger; impl log::Log for Logger { @@ -119,10 +125,7 @@ impl From<tokio::net::TcpStream> for TcpStream { fn create_js_runtime() -> JsRuntime { let ext = deno_core::Extension::builder() - .ops(vec![ - ("listen", deno_core::op_sync(op_listen)), - ("accept", deno_core::op_async(op_accept)), - ]) + .ops(vec![op_listen::decl(), op_accept::decl()]) .build(); JsRuntime::new(deno_core::RuntimeOptions { @@ -131,6 +134,7 @@ fn create_js_runtime() -> JsRuntime { }) } +#[op] fn op_listen(state: &mut OpState, _: (), _: ()) -> Result<ResourceId, Error> { log::debug!("listen"); let addr = "127.0.0.1:4544".parse::<SocketAddr>().unwrap(); @@ -141,6 +145,7 @@ fn op_listen(state: &mut OpState, _: (), _: ()) -> Result<ResourceId, Error> { Ok(rid) } +#[op] async fn op_accept( state: Rc<RefCell<OpState>>, rid: ResourceId, |