summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs10
-rw-r--r--src/isolate.rs3
-rw-r--r--src/msg.fbs5
3 files changed, 18 insertions, 0 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index c914df36d..42becc0b0 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -45,6 +45,7 @@ pub fn msg_from_js(state: Arc<IsolateState>, bytes: &[u8]) -> (bool, Box<Op>) {
msg::Any::Start => handle_start,
msg::Any::CodeFetch => handle_code_fetch,
msg::Any::CodeCache => handle_code_cache,
+ msg::Any::SetTimeout => handle_set_timeout,
msg::Any::Environ => handle_env,
msg::Any::FetchReq => handle_fetch_req,
msg::Any::TimerStart => handle_timer_start,
@@ -236,6 +237,15 @@ fn handle_code_cache(state: Arc<IsolateState>, base: &msg::Base) -> Box<Op> {
}()))
}
+fn handle_set_timeout(state: Arc<IsolateState>, base: &msg::Base) -> Box<Op> {
+ let msg = base.msg_as_set_timeout().unwrap();
+ let val = msg.timeout() as isize;
+ state
+ .timeout
+ .swap(val, std::sync::atomic::Ordering::Relaxed);
+ ok_future(empty_buf())
+}
+
fn handle_set_env(state: Arc<IsolateState>, base: &msg::Base) -> Box<Op> {
let msg = base.msg_as_set_env().unwrap();
let key = msg.key().unwrap();
diff --git a/src/isolate.rs b/src/isolate.rs
index 64bec5ddf..30e90be5c 100644
--- a/src/isolate.rs
+++ b/src/isolate.rs
@@ -16,6 +16,7 @@ use std;
use std::collections::HashMap;
use std::ffi::CStr;
use std::ffi::CString;
+use std::sync::atomic::AtomicIsize;
use std::sync::mpsc;
use std::sync::Arc;
use std::sync::Mutex;
@@ -48,6 +49,7 @@ pub struct Isolate {
// Isolate cannot be passed between threads but IsolateState can. So any state that
// needs to be accessed outside the main V8 thread should be inside IsolateState.
pub struct IsolateState {
+ pub timeout: AtomicIsize,
pub dir: deno_dir::DenoDir,
pub timers: Mutex<HashMap<u32, futures::sync::oneshot::Sender<()>>>,
pub argv: Vec<String>,
@@ -85,6 +87,7 @@ impl Isolate {
rx,
ntasks: 0,
state: Arc::new(IsolateState {
+ timeout: AtomicIsize::new(-1),
dir: deno_dir::DenoDir::new(flags.reload, None).unwrap(),
timers: Mutex::new(HashMap::new()),
argv: argv_rest,
diff --git a/src/msg.fbs b/src/msg.fbs
index 6358668b7..52eba8ca6 100644
--- a/src/msg.fbs
+++ b/src/msg.fbs
@@ -4,6 +4,7 @@ union Any {
CodeFetch,
CodeFetchRes,
CodeCache,
+ SetTimeout,
Exit,
TimerStart,
TimerReady,
@@ -115,6 +116,10 @@ table CodeCache {
output_code: string;
}
+table SetTimeout {
+ timeout: int;
+}
+
table Exit {
code: int;
}