diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-09-12 00:10:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-12 00:10:43 +0200 |
commit | bdeb4bddbf5cabd04abe906388f5ebfe64a84c53 (patch) | |
tree | fd6aed583eac5108c4403ae424bc4246781bed0c /runtime/ops/process.rs | |
parent | aaff69db3fd8cf70d1c031720e84874cb4a4d02c (diff) |
refactor: rewrite runtime/ ops to op2 (#20459)
Diffstat (limited to 'runtime/ops/process.rs')
-rw-r--r-- | runtime/ops/process.rs | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 0b9a95c55..acfd0dc5c 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -6,6 +6,7 @@ use deno_core::anyhow::Context; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op; +use deno_core::op2; use deno_core::serde_json; use deno_core::AsyncMutFuture; use deno_core::AsyncRefCell; @@ -322,16 +323,18 @@ fn spawn_child( }) } -#[op] +#[op2] +#[serde] fn op_spawn_child( state: &mut OpState, - args: SpawnArgs, - api_name: String, + #[serde] args: SpawnArgs, + #[string] api_name: String, ) -> Result<Child, AnyError> { let command = create_command(state, args, &api_name)?; spawn_child(state, command) } +// TODO(bartlomieju): op2 doesn't support clippy allows #[op] async fn op_spawn_wait( state: Rc<RefCell<OpState>>, @@ -351,10 +354,11 @@ async fn op_spawn_wait( result } -#[op] +#[op2] +#[serde] fn op_spawn_sync( state: &mut OpState, - args: SpawnArgs, + #[serde] args: SpawnArgs, ) -> Result<SpawnOutput, AnyError> { let stdout = matches!(args.stdio.stdout, Stdio::Piped); let stderr = matches!(args.stdio.stderr, Stdio::Piped); @@ -381,11 +385,11 @@ fn op_spawn_sync( }) } -#[op] +#[op2(fast)] fn op_spawn_kill( state: &mut OpState, - rid: ResourceId, - signal: String, + #[smi] rid: ResourceId, + #[string] signal: String, ) -> Result<(), AnyError> { if let Ok(child_resource) = state.resource_table.get::<ChildResource>(rid) { deprecated::kill(child_resource.1 as i32, &signal)?; @@ -432,7 +436,7 @@ mod deprecated { #[derive(Serialize)] #[serde(rename_all = "camelCase")] // TODO(@AaronO): maybe find a more descriptive name or a convention for return structs - struct RunInfo { + pub struct RunInfo { rid: ResourceId, pid: Option<u32>, stdin_rid: Option<ResourceId>, @@ -440,10 +444,11 @@ mod deprecated { stderr_rid: Option<ResourceId>, } - #[op] - fn op_run( + #[op2] + #[serde] + pub fn op_run( state: &mut OpState, - run_args: RunArgs, + #[serde] run_args: RunArgs, ) -> Result<RunInfo, AnyError> { let args = run_args.cmd; state @@ -557,16 +562,17 @@ mod deprecated { #[derive(Serialize)] #[serde(rename_all = "camelCase")] - struct ProcessStatus { + pub struct ProcessStatus { got_signal: bool, exit_code: i32, exit_signal: i32, } - #[op] - async fn op_run_status( + #[op2(async)] + #[serde] + pub async fn op_run_status( state: Rc<RefCell<OpState>>, - rid: ResourceId, + #[smi] rid: ResourceId, ) -> Result<ProcessStatus, AnyError> { let resource = state .borrow_mut() @@ -648,12 +654,12 @@ mod deprecated { } } - #[op] - fn op_kill( + #[op2(fast)] + pub fn op_kill( state: &mut OpState, - pid: i32, - signal: String, - api_name: String, + #[smi] pid: i32, + #[string] signal: String, + #[string] api_name: String, ) -> Result<(), AnyError> { state .borrow_mut::<PermissionsContainer>() |