feat(core): sync io ops in core (#18603)

This commit adds op_read_sync and op_write_sync to core. These ops are
similar to op_read and op_write, but they are synchronous. Just like the
async ops, they operate on generic `deno_core::Resource` objects. These
now have new `read_byob_sync` and `write_sync` methods, with default
implementations throwing "NotSupported" errors, just like the async
counterparts.

There are no `write_all` or `read` equivalents, because the
optimizations they unlock are not useful in synchronous contexts.
This commit is contained in:
Luca Casonato 2023-04-06 00:14:16 +02:00 committed by GitHub
parent ee15b49845
commit 36e8c8dfd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 54 deletions

View file

@ -60,6 +60,16 @@ declare namespace Deno {
*/
function writeAll(rid: number, buf: Uint8Array): Promise<void>;
/**
* Synchronously read from a (stream) resource that implements readSync().
*/
function readSync(rid: number, buf: Uint8Array): number;
/**
* Synchronously write to a (stream) resource that implements writeSync().
*/
function writeSync(rid: number, buf: Uint8Array): number;
/**
* Print a message to stdout or stderr
*/