summaryrefslogtreecommitdiff
path: root/runtime/ops/signal.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-04-05 18:40:24 +0200
committerGitHub <noreply@github.com>2021-04-05 18:40:24 +0200
commit2aed322dd507a8568b6ee6f4897e9a8e3220f763 (patch)
treee9a45c0b7688a9881ea9ce132b92554ef2955ad6 /runtime/ops/signal.rs
parent284e6c303956e8ca20af63b4ecc045438a260fe6 (diff)
refactor: convert ops to use serde_v8 (#10009)
This commit rewrites most of the ops to use "serde_v8" instead of "json" serialization.
Diffstat (limited to 'runtime/ops/signal.rs')
-rw-r--r--runtime/ops/signal.rs57
1 files changed, 18 insertions, 39 deletions
diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs
index ef29ddec7..5235da612 100644
--- a/runtime/ops/signal.rs
+++ b/runtime/ops/signal.rs
@@ -1,6 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::AnyError;
-use deno_core::serde_json::Value;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use std::cell::RefCell;
@@ -9,8 +8,6 @@ use std::rc::Rc;
#[cfg(unix)]
use deno_core::error::bad_resource_id;
#[cfg(unix)]
-use deno_core::serde_json::json;
-#[cfg(unix)]
use deno_core::AsyncRefCell;
#[cfg(unix)]
use deno_core::CancelFuture;
@@ -21,7 +18,7 @@ use deno_core::RcRef;
#[cfg(unix)]
use deno_core::Resource;
#[cfg(unix)]
-use serde::Deserialize;
+use deno_core::ResourceId;
#[cfg(unix)]
use std::borrow::Cow;
#[cfg(unix)]
@@ -53,45 +50,28 @@ impl Resource for SignalStreamResource {
}
#[cfg(unix)]
-#[derive(Deserialize)]
-pub struct BindSignalArgs {
- signo: i32,
-}
-
-#[cfg(unix)]
-#[derive(Deserialize)]
-pub struct SignalArgs {
- rid: u32,
-}
-
-#[cfg(unix)]
#[allow(clippy::unnecessary_wraps)]
fn op_signal_bind(
state: &mut OpState,
- args: BindSignalArgs,
+ signo: i32,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<Value, AnyError> {
+) -> Result<ResourceId, AnyError> {
super::check_unstable(state, "Deno.signal");
let resource = SignalStreamResource {
- signal: AsyncRefCell::new(
- signal(SignalKind::from_raw(args.signo)).expect(""),
- ),
+ signal: AsyncRefCell::new(signal(SignalKind::from_raw(signo)).expect("")),
cancel: Default::default(),
};
let rid = state.resource_table.add(resource);
- Ok(json!({
- "rid": rid,
- }))
+ Ok(rid)
}
#[cfg(unix)]
async fn op_signal_poll(
state: Rc<RefCell<OpState>>,
- args: SignalArgs,
+ rid: ResourceId,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<Value, AnyError> {
+) -> Result<bool, AnyError> {
super::check_unstable2(&state, "Deno.signal");
- let rid = args.rid;
let resource = state
.borrow_mut()
@@ -102,49 +82,48 @@ async fn op_signal_poll(
let mut signal = RcRef::map(&resource, |r| &r.signal).borrow_mut().await;
match signal.recv().or_cancel(cancel).await {
- Ok(result) => Ok(json!({ "done": result.is_none() })),
- Err(_) => Ok(json!({ "done": true })),
+ Ok(result) => Ok(result.is_none()),
+ Err(_) => Ok(true),
}
}
#[cfg(unix)]
pub fn op_signal_unbind(
state: &mut OpState,
- args: SignalArgs,
+ rid: ResourceId,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<Value, AnyError> {
+) -> Result<(), AnyError> {
super::check_unstable(state, "Deno.signal");
- let rid = args.rid;
state
.resource_table
.close(rid)
.ok_or_else(bad_resource_id)?;
- Ok(json!({}))
+ Ok(())
}
#[cfg(not(unix))]
pub fn op_signal_bind(
_state: &mut OpState,
- _args: Value,
+ _args: (),
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<Value, AnyError> {
+) -> Result<(), AnyError> {
unimplemented!();
}
#[cfg(not(unix))]
fn op_signal_unbind(
_state: &mut OpState,
- _args: Value,
+ _args: (),
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<Value, AnyError> {
+) -> Result<(), AnyError> {
unimplemented!();
}
#[cfg(not(unix))]
async fn op_signal_poll(
_state: Rc<RefCell<OpState>>,
- _args: Value,
+ _args: (),
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<Value, AnyError> {
+) -> Result<(), AnyError> {
unimplemented!();
}