mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
2235dd795d
* Revert "port more ops to JSON (#2809)" This reverts commit137f33733d
. * Revert "port ops to JSON: compiler, errors, fetch, files (#2804)" This reverts commit79f82cf10e
. * Revert "Port rest of os ops to JSON (#2802)" This reverts commit5b2baa5c99
.
63 lines
1.6 KiB
Rust
63 lines
1.6 KiB
Rust
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
use super::dispatch_flatbuffers::serialize_response;
|
|
use super::utils::empty_buf;
|
|
use super::utils::CliOpResult;
|
|
use crate::deno_error;
|
|
use crate::msg;
|
|
use crate::state::ThreadSafeState;
|
|
use deno::*;
|
|
use flatbuffers::FlatBufferBuilder;
|
|
use futures::Future;
|
|
use std;
|
|
use std::time::Duration;
|
|
use std::time::Instant;
|
|
|
|
pub fn op_global_timer_stop(
|
|
state: &ThreadSafeState,
|
|
base: &msg::Base<'_>,
|
|
data: Option<PinnedBuf>,
|
|
) -> CliOpResult {
|
|
if !base.sync() {
|
|
return Err(deno_error::no_async_support());
|
|
}
|
|
assert!(data.is_none());
|
|
let state = state;
|
|
let mut t = state.global_timer.lock().unwrap();
|
|
t.cancel();
|
|
Ok(Op::Sync(empty_buf()))
|
|
}
|
|
|
|
pub fn op_global_timer(
|
|
state: &ThreadSafeState,
|
|
base: &msg::Base<'_>,
|
|
data: Option<PinnedBuf>,
|
|
) -> CliOpResult {
|
|
if base.sync() {
|
|
return Err(deno_error::no_sync_support());
|
|
}
|
|
assert!(data.is_none());
|
|
let cmd_id = base.cmd_id();
|
|
let inner = base.inner_as_global_timer().unwrap();
|
|
let val = inner.timeout();
|
|
assert!(val >= 0);
|
|
|
|
let state = state;
|
|
let mut t = state.global_timer.lock().unwrap();
|
|
let deadline = Instant::now() + Duration::from_millis(val as u64);
|
|
let f = t.new_timeout(deadline);
|
|
|
|
Ok(Op::Async(Box::new(f.then(move |_| {
|
|
let builder = &mut FlatBufferBuilder::new();
|
|
let inner =
|
|
msg::GlobalTimerRes::create(builder, &msg::GlobalTimerResArgs {});
|
|
Ok(serialize_response(
|
|
cmd_id,
|
|
builder,
|
|
msg::BaseArgs {
|
|
inner: Some(inner.as_union_value()),
|
|
inner_type: msg::Any::GlobalTimerRes,
|
|
..Default::default()
|
|
},
|
|
))
|
|
}))))
|
|
}
|