Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
675919e9
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,发现更多精彩内容 >>
未验证
提交
675919e9
编写于
4月 23, 2019
作者:
R
Ryan Dahl
提交者:
GitHub
4月 23, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use tokio_threadpool's new panic_handler (#2188)
上级
6caf8655
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
21 deletion
+19
-21
cli/compiler.rs
cli/compiler.rs
+1
-3
cli/tokio_util.rs
cli/tokio_util.rs
+18
-18
未找到文件。
cli/compiler.rs
浏览文件 @
675919e9
...
@@ -35,7 +35,7 @@ lazy_static! {
...
@@ -35,7 +35,7 @@ lazy_static! {
static
ref
C_RID
:
Mutex
<
Option
<
ResourceId
>>
=
Mutex
::
new
(
None
);
static
ref
C_RID
:
Mutex
<
Option
<
ResourceId
>>
=
Mutex
::
new
(
None
);
// tokio runtime specifically for spawning logic that is dependent on
// tokio runtime specifically for spawning logic that is dependent on
// completetion of the compiler worker future
// completetion of the compiler worker future
static
ref
C_RUNTIME
:
Mutex
<
Runtime
>
=
Mutex
::
new
(
Runtime
::
new
()
.unwrap
());
static
ref
C_RUNTIME
:
Mutex
<
Runtime
>
=
Mutex
::
new
(
tokio_util
::
create_threadpool_runtime
());
}
}
// This corresponds to JS ModuleMetaData.
// This corresponds to JS ModuleMetaData.
...
@@ -111,8 +111,6 @@ fn lazy_start(parent_state: ThreadSafeState) -> ResourceId {
...
@@ -111,8 +111,6 @@ fn lazy_start(parent_state: ThreadSafeState) -> ResourceId {
let
mut
runtime
=
C_RUNTIME
.lock
()
.unwrap
();
let
mut
runtime
=
C_RUNTIME
.lock
()
.unwrap
();
runtime
.spawn
(
lazy
(
move
||
{
runtime
.spawn
(
lazy
(
move
||
{
tokio_util
::
abort_on_panic
();
worker
.then
(
move
|
result
|
->
Result
<
(),
()
>
{
worker
.then
(
move
|
result
|
->
Result
<
(),
()
>
{
// Close resource so the future created by
// Close resource so the future created by
// handle_worker_message_stream exits
// handle_worker_message_stream exits
...
...
cli/tokio_util.rs
浏览文件 @
675919e9
...
@@ -8,25 +8,28 @@ use std::mem;
...
@@ -8,25 +8,28 @@ use std::mem;
use
std
::
net
::
SocketAddr
;
use
std
::
net
::
SocketAddr
;
use
tokio
;
use
tokio
;
use
tokio
::
net
::
TcpStream
;
use
tokio
::
net
::
TcpStream
;
use
tokio
::
runtime
;
pub
fn
create_threadpool_runtime
()
->
tokio
::
runtime
::
Runtime
{
// This code can be simplified once the following PR is landed and
// released: https://github.com/tokio-rs/tokio/pull/1055
use
tokio_threadpool
::
Builder
as
ThreadPoolBuilder
;
let
mut
threadpool_builder
=
ThreadPoolBuilder
::
new
();
threadpool_builder
.panic_handler
(|
err
|
std
::
panic
::
resume_unwind
(
err
));
#[allow(deprecated)]
runtime
::
Builder
::
new
()
.threadpool_builder
(
threadpool_builder
)
.build
()
.unwrap
()
}
pub
fn
run
<
F
>
(
future
:
F
)
pub
fn
run
<
F
>
(
future
:
F
)
where
where
F
:
Future
<
Item
=
(),
Error
=
()
>
+
Send
+
'static
,
F
:
Future
<
Item
=
(),
Error
=
()
>
+
Send
+
'static
,
{
{
abort_on_panic
();
// tokio::runtime::current_thread::run(future)
// tokio::runtime::current_thread::run(future)
tokio
::
run
(
future
)
let
rt
=
create_threadpool_runtime
();
}
rt
.block_on_all
(
future
)
.unwrap
();
// Tokio swallows panics. In order to actually crash when we panic, we
// have to set this custom hook.
// https://github.com/tokio-rs/tokio/issues/495
// https://github.com/tokio-rs/tokio/issues/209
pub
fn
abort_on_panic
()
{
std
::
panic
::
set_hook
(
Box
::
new
(|
panic_info
|
{
eprintln!
(
"{}"
,
panic_info
.to_string
());
std
::
process
::
abort
();
}));
}
}
pub
fn
block_on
<
F
,
R
,
E
>
(
future
:
F
)
->
Result
<
R
,
E
>
pub
fn
block_on
<
F
,
R
,
E
>
(
future
:
F
)
->
Result
<
R
,
E
>
...
@@ -48,13 +51,10 @@ pub fn init<F>(f: F)
...
@@ -48,13 +51,10 @@ pub fn init<F>(f: F)
where
where
F
:
FnOnce
(),
F
:
FnOnce
(),
{
{
let
rt
=
tokio
::
runtime
::
Runtime
::
new
()
.unwrap
();
let
rt
=
create_threadpool_runtime
();
let
mut
executor
=
rt
.executor
();
let
mut
executor
=
rt
.executor
();
let
mut
enter
=
tokio_executor
::
enter
()
.expect
(
"Multiple executors at once"
);
let
mut
enter
=
tokio_executor
::
enter
()
.expect
(
"Multiple executors at once"
);
tokio_executor
::
with_default
(
&
mut
executor
,
&
mut
enter
,
move
|
_
enter
|
{
tokio_executor
::
with_default
(
&
mut
executor
,
&
mut
enter
,
move
|
_
enter
|
f
());
abort_on_panic
();
f
()
});
}
}
#[derive(Debug)]
#[derive(Debug)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录