summaryrefslogtreecommitdiff
path: root/core/resources.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2023-04-06 00:14:16 +0200
committerGitHub <noreply@github.com>2023-04-06 00:14:16 +0200
commit36e8c8dfd759458aa735f79f5cc7cd346c727914 (patch)
treeca8065958c406c02a8daa56f5056a658c813839f /core/resources.rs
parentee15b49845b9cbe1f8ea75372091931fa460ad0d (diff)
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.
Diffstat (limited to 'core/resources.rs')
-rw-r--r--core/resources.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/resources.rs b/core/resources.rs
index 5bec68481..6ca86e10b 100644
--- a/core/resources.rs
+++ b/core/resources.rs
@@ -154,6 +154,18 @@ pub trait Resource: Any + 'static {
})
}
+ /// The same as [`read_byob()`][Resource::read_byob], but synchronous.
+ fn read_byob_sync(&self, data: &mut [u8]) -> Result<usize, Error> {
+ _ = data;
+ Err(not_supported())
+ }
+
+ /// The same as [`write()`][Resource::write], but synchronous.
+ fn write_sync(&self, data: &[u8]) -> Result<usize, Error> {
+ _ = data;
+ Err(not_supported())
+ }
+
/// The shutdown method can be used to asynchronously close the resource. It
/// is not automatically called when the resource is dropped or closed.
///