Skip to content

Commit

Permalink
docs: add document for the waker in SignalStreamResource
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Jan 23, 2020
1 parent f7c2648 commit fe55b49
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cli/ops/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use super::dispatch_json::Deserialize;
#[cfg(unix)]
use crate::deno_error::bad_resource;
#[cfg(unix)]
use std::task::Waker;
#[cfg(unix)]
use deno_core::Resource;
#[cfg(unix)]
use futures::future::{poll_fn, FutureExt};
#[cfg(unix)]
use serde_json;
#[cfg(unix)]
use std::task::Waker;
#[cfg(unix)]
use tokio::signal::unix::{signal, Signal, SignalKind};

pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
Expand All @@ -35,6 +35,8 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
}

#[cfg(unix)]
/// The resource for signal stream.
/// The second element is the waker of polling future.
pub struct SignalStreamResource(pub Signal, pub Option<Waker>);

#[cfg(unix)]
Expand Down Expand Up @@ -113,6 +115,8 @@ pub fn op_unbind_signal(
let resource = table.get::<SignalStreamResource>(rid);
if let Some(signal) = resource {
if let Some(waker) = &signal.1 {
// Wakes up the pending poll if exists.
// This prevents the poll future from getting stuck forever.
waker.clone().wake();
}
}
Expand Down

0 comments on commit fe55b49

Please sign in to comment.