summaryrefslogtreecommitdiff
path: root/core/ops_builtin.rs
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2021-09-10 15:47:09 -0700
committerGitHub <noreply@github.com>2021-09-10 15:47:09 -0700
commitfa963909e5c48cacd60cc02db200927611fa8e91 (patch)
tree049887e4cbdc3cd9538077fa23d461814b671041 /core/ops_builtin.rs
parent87052927afd505ff1c5d42075cd23a3619b29011 (diff)
perf(ext/http): optimize auto cleanup of request resource (#11978)
Fixes #11963.
Diffstat (limited to 'core/ops_builtin.rs')
-rw-r--r--core/ops_builtin.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs
index 459b2a967..06de59054 100644
--- a/core/ops_builtin.rs
+++ b/core/ops_builtin.rs
@@ -17,6 +17,7 @@ pub(crate) fn init_builtins() -> Extension {
))
.ops(vec![
("op_close", op_sync(op_close)),
+ ("op_try_close", op_sync(op_try_close)),
("op_print", op_sync(op_print)),
("op_resources", op_sync(op_resources)),
])
@@ -44,10 +45,24 @@ pub fn op_close(
rid: Option<ResourceId>,
_: (),
) -> Result<(), AnyError> {
- // TODO(@AaronO): drop Option after improving type-strictness balance in serde_v8
+ // TODO(@AaronO): drop Option after improving type-strictness balance in
+ // serde_v8
let rid = rid.ok_or_else(|| type_error("missing or invalid `rid`"))?;
state.resource_table.close(rid)?;
+ Ok(())
+}
+/// Try to remove a resource from the resource table. If there is no resource
+/// with the specified `rid`, this is a no-op.
+pub fn op_try_close(
+ state: &mut OpState,
+ rid: Option<ResourceId>,
+ _: (),
+) -> Result<(), AnyError> {
+ // TODO(@AaronO): drop Option after improving type-strictness balance in
+ // serde_v8.
+ let rid = rid.ok_or_else(|| type_error("missing or invalid `rid`"))?;
+ let _ = state.resource_table.close(rid);
Ok(())
}