diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-03-14 23:14:15 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 18:44:15 +0100 |
commit | b4e42953e1d243f2eda20e5be6b845d60b7bf688 (patch) | |
tree | 10b3bfff165f9c04f9174c7c399d44b9b724c3b3 /core/examples/http_bench_json_ops.rs | |
parent | 4e3ed37037a2aa1edeac260dc3463a81d9cf9b88 (diff) |
feat(core): codegen ops (#13861)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
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, |