diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/01_core.js | 1 | ||||
-rw-r--r-- | core/examples/http_bench_json_ops.js | 2 | ||||
-rw-r--r-- | core/lib.deno_core.d.ts | 5 | ||||
-rw-r--r-- | core/ops_builtin.rs | 13 |
4 files changed, 20 insertions, 1 deletions
diff --git a/core/01_core.js b/core/01_core.js index 655b4219e..b98e54160 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -329,6 +329,7 @@ tryClose: (rid) => ops.op_try_close(rid), read: opAsync.bind(null, "op_read"), write: opAsync.bind(null, "op_write"), + writeAll: opAsync.bind(null, "op_write_all"), shutdown: opAsync.bind(null, "op_shutdown"), print: (msg, isErr) => ops.op_print(msg, isErr), setMacrotaskCallback: (fn) => ops.op_set_macrotask_callback(fn), diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js index cea344987..98b2f4ef8 100644 --- a/core/examples/http_bench_json_ops.js +++ b/core/examples/http_bench_json_ops.js @@ -23,7 +23,7 @@ async function serve(rid) { try { while (true) { await Deno.core.read(rid, requestBuf); - await Deno.core.write(rid, responseBuf); + await Deno.core.writeAll(rid, responseBuf); } } catch (e) { if ( diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts index 7e46d0f14..2a3764730 100644 --- a/core/lib.deno_core.d.ts +++ b/core/lib.deno_core.d.ts @@ -62,6 +62,11 @@ declare namespace Deno { function write(rid: number, buf: Uint8Array): Promise<number>; /** + * Write to a (stream) resource that implements write() + */ + function writeAll(rid: number, buf: Uint8Array): Promise<void>; + + /** * Print a message to stdout or stderr */ function print(message: string, is_err?: boolean): void; diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 41741bf28..3fc9d62d6 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -38,6 +38,7 @@ pub(crate) fn init_builtins() -> Extension { op_read::decl(), op_read_all::decl(), op_write::decl(), + op_write_all::decl(), op_shutdown::decl(), op_metrics::decl(), op_format_file_name::decl(), @@ -254,6 +255,18 @@ async fn op_write( } #[op] +async fn op_write_all( + state: Rc<RefCell<OpState>>, + rid: ResourceId, + buf: ZeroCopyBuf, +) -> Result<(), Error> { + let resource = state.borrow().resource_table.get_any(rid)?; + let view = BufView::from(buf); + resource.write_all(view).await?; + Ok(()) +} + +#[op] async fn op_shutdown( state: Rc<RefCell<OpState>>, rid: ResourceId, |