Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
4eeda9ea
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
4eeda9ea
编写于
10月 02, 2018
作者:
B
Bert Belder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
timers: remove the old timer implementation
Fixes #878.
上级
99e2c42d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1 addition
and
115 deletion
+1
-115
src/handlers.rs
src/handlers.rs
+0
-94
src/isolate.rs
src/isolate.rs
+1
-4
src/msg.fbs
src/msg.fbs
+0
-17
未找到文件。
src/handlers.rs
浏览文件 @
4eeda9ea
...
...
@@ -13,7 +13,6 @@ use msg;
use
flatbuffers
::
FlatBufferBuilder
;
use
futures
;
use
futures
::
future
::
poll_fn
;
use
futures
::
sync
::
oneshot
;
use
futures
::
Poll
;
use
hyper
;
use
hyper
::
rt
::{
Future
,
Stream
};
...
...
@@ -30,7 +29,6 @@ use std::sync::Arc;
use
std
::
time
::
UNIX_EPOCH
;
use
std
::
time
::{
Duration
,
Instant
};
use
tokio
;
use
tokio
::
timer
::
Delay
;
use
tokio_io
;
use
tokio_threadpool
;
...
...
@@ -71,8 +69,6 @@ pub fn msg_from_js(
msg
::
Any
::
CodeCache
=>
handle_code_cache
,
msg
::
Any
::
Environ
=>
handle_env
,
msg
::
Any
::
FetchReq
=>
handle_fetch_req
,
msg
::
Any
::
TimerStart
=>
handle_timer_start
,
msg
::
Any
::
TimerClear
=>
handle_timer_clear
,
msg
::
Any
::
MakeTempDir
=>
handle_make_temp_dir
,
msg
::
Any
::
Mkdir
=>
handle_mkdir
,
msg
::
Any
::
Open
=>
handle_open
,
...
...
@@ -446,30 +442,6 @@ fn handle_fetch_req(
Box
::
new
(
future
)
}
fn
set_timeout
<
F
>
(
cb
:
F
,
delay
:
u32
,
)
->
(
impl
Future
<
Item
=
(),
Error
=
()
>
,
futures
::
sync
::
oneshot
::
Sender
<
()
>
,
)
where
F
:
FnOnce
()
->
(),
{
let
(
cancel_tx
,
cancel_rx
)
=
oneshot
::
channel
::
<
()
>
();
let
when
=
Instant
::
now
()
+
Duration
::
from_millis
(
delay
.into
());
let
delay_task
=
Delay
::
new
(
when
)
.map_err
(|
e
|
panic!
(
"timer failed; err={:?}"
,
e
))
.and_then
(|
_
|
{
cb
();
Ok
(())
})
.select
(
cancel_rx
)
.map
(|
_
|
())
.map_err
(|
_
|
());
(
delay_task
,
cancel_tx
)
}
// This is just type conversion. Implement From trait?
// See https://github.com/tokio-rs/tokio/blob/ffd73a64e7ec497622b7f939e38017afe7124dc4/tokio-fs/src/lib.rs#L76-L85
fn
convert_blocking
<
F
>
(
f
:
F
)
->
Poll
<
Buf
,
DenoError
>
...
...
@@ -865,72 +837,6 @@ fn handle_write_file(
})
}
fn
remove_timer
(
state
:
Arc
<
IsolateState
>
,
timer_id
:
u32
)
{
let
mut
timers
=
state
.timers
.lock
()
.unwrap
();
timers
.remove
(
&
timer_id
);
}
// Prototype: https://github.com/ry/isolate/blob/golang/timers.go#L25-L39
fn
handle_timer_start
(
state
:
Arc
<
IsolateState
>
,
base
:
&
msg
::
Base
,
data
:
&
'static
mut
[
u8
],
)
->
Box
<
Op
>
{
assert_eq!
(
data
.len
(),
0
);
debug!
(
"handle_timer_start"
);
let
msg
=
base
.msg_as_timer_start
()
.unwrap
();
let
cmd_id
=
base
.cmd_id
();
let
timer_id
=
msg
.id
();
let
delay
=
msg
.delay
();
let
config2
=
state
.clone
();
let
future
=
{
let
(
delay_task
,
cancel_delay
)
=
set_timeout
(
move
||
{
remove_timer
(
config2
,
timer_id
);
},
delay
,
);
let
mut
timers
=
state
.timers
.lock
()
.unwrap
();
timers
.insert
(
timer_id
,
cancel_delay
);
delay_task
};
let
r
=
Box
::
new
(
future
.then
(
move
|
result
|
{
let
builder
=
&
mut
FlatBufferBuilder
::
new
();
let
msg
=
msg
::
TimerReady
::
create
(
builder
,
&
msg
::
TimerReadyArgs
{
id
:
timer_id
,
canceled
:
result
.is_err
(),
..
Default
::
default
()
},
);
Ok
(
serialize_response
(
cmd_id
,
builder
,
msg
::
BaseArgs
{
msg
:
Some
(
msg
.as_union_value
()),
msg_type
:
msg
::
Any
::
TimerReady
,
..
Default
::
default
()
},
))
}));
r
}
// Prototype: https://github.com/ry/isolate/blob/golang/timers.go#L40-L43
fn
handle_timer_clear
(
state
:
Arc
<
IsolateState
>
,
base
:
&
msg
::
Base
,
data
:
&
'static
mut
[
u8
],
)
->
Box
<
Op
>
{
assert_eq!
(
data
.len
(),
0
);
let
msg
=
base
.msg_as_timer_clear
()
.unwrap
();
debug!
(
"handle_timer_clear"
);
remove_timer
(
state
,
msg
.id
());
ok_future
(
empty_buf
())
}
fn
handle_rename
(
state
:
Arc
<
IsolateState
>
,
base
:
&
msg
::
Base
,
...
...
src/isolate.rs
浏览文件 @
4eeda9ea
...
...
@@ -9,11 +9,9 @@ use errors::DenoError;
use
flags
;
use
libdeno
;
use
futures
;
use
futures
::
Future
;
use
libc
::
c_void
;
use
std
;
use
std
::
collections
::
HashMap
;
use
std
::
ffi
::
CStr
;
use
std
::
ffi
::
CString
;
use
std
::
sync
::
mpsc
;
...
...
@@ -54,7 +52,6 @@ pub struct Isolate {
// needs to be accessed outside the main V8 thread should be inside IsolateState.
pub
struct
IsolateState
{
pub
dir
:
deno_dir
::
DenoDir
,
pub
timers
:
Mutex
<
HashMap
<
u32
,
futures
::
sync
::
oneshot
::
Sender
<
()
>>>
,
pub
argv
:
Vec
<
String
>
,
pub
flags
:
flags
::
DenoFlags
,
tx
:
Mutex
<
Option
<
mpsc
::
Sender
<
(
i32
,
Buf
)
>>>
,
...
...
@@ -92,7 +89,6 @@ impl Isolate {
timeout_due
:
None
,
state
:
Arc
::
new
(
IsolateState
{
dir
:
deno_dir
::
DenoDir
::
new
(
flags
.reload
,
None
)
.unwrap
(),
timers
:
Mutex
::
new
(
HashMap
::
new
()),
argv
:
argv_rest
,
flags
,
tx
:
Mutex
::
new
(
Some
(
tx
)),
...
...
@@ -280,6 +276,7 @@ extern "C" fn pre_dispatch(
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
futures
;
#[test]
fn
test_c_to_rust
()
{
...
...
src/msg.fbs
浏览文件 @
4eeda9ea
...
...
@@ -6,9 +6,6 @@ union Any {
CodeCache,
SetTimeout,
Exit,
TimerStart,
TimerReady,
TimerClear,
Environ,
EnvironRes,
FetchReq,
...
...
@@ -135,20 +132,6 @@ table Exit {
code: int;
}
table TimerStart {
id: uint;
delay: uint;
}
table TimerReady {
id: uint;
canceled: bool;
}
table TimerClear {
id: uint;
}
table Environ {}
table SetEnv {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录