Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
61231912
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,发现更多精彩内容 >>
提交
61231912
编写于
9月 12, 2019
作者:
B
Bartek Iwańczuk
提交者:
Ryan Dahl
9月 11, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: panicking when can't create runtime for block_on (#2905)
上级
19cd8dea
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
11 deletion
+17
-11
cli/tokio_util.rs
cli/tokio_util.rs
+17
-11
未找到文件。
cli/tokio_util.rs
浏览文件 @
61231912
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use
crate
::
resources
::
Resource
;
use
deno
::
ErrBox
;
use
futures
;
use
futures
::
Future
;
use
futures
::
Poll
;
...
...
@@ -10,11 +11,11 @@ use tokio;
use
tokio
::
net
::
TcpStream
;
use
tokio
::
runtime
;
pub
fn
create_threadpool_runtime
()
->
tokio
::
runtime
::
Runtime
{
pub
fn
create_threadpool_runtime
(
)
->
Result
<
tokio
::
runtime
::
Runtime
,
tokio
::
io
::
Error
>
{
runtime
::
Builder
::
new
()
.panic_handler
(|
err
|
std
::
panic
::
resume_unwind
(
err
))
.build
()
.unwrap
()
}
pub
fn
run
<
F
>
(
future
:
F
)
...
...
@@ -22,7 +23,7 @@ where
F
:
Future
<
Item
=
(),
Error
=
()
>
+
Send
+
'static
,
{
// tokio::runtime::current_thread::run(future)
let
rt
=
create_threadpool_runtime
();
let
rt
=
create_threadpool_runtime
()
.expect
(
"Unable to create Tokio runtime"
)
;
rt
.block_on_all
(
future
)
.unwrap
();
}
...
...
@@ -39,22 +40,27 @@ where
/// given future. This is useful when we want to block the main runtime to
/// resolve a future without worrying that we'll use up all the threads in the
/// main runtime.
pub
fn
block_on
<
F
,
R
,
E
>
(
future
:
F
)
->
Result
<
R
,
E
>
pub
fn
block_on
<
F
,
R
>
(
future
:
F
)
->
Result
<
R
,
ErrBox
>
where
F
:
Send
+
'static
+
Future
<
Item
=
R
,
Error
=
E
>
,
F
:
Send
+
'static
+
Future
<
Item
=
R
,
Error
=
E
rrBox
>
,
R
:
Send
+
'static
,
E
:
Send
+
'static
,
{
use
std
::
sync
::
mpsc
::
channel
;
use
std
::
thread
;
let
(
sender
,
receiver
)
=
channel
();
// Create a new runtime to evaluate the future asynchronously.
thread
::
spawn
(
move
||
{
let
mut
rt
=
create_threadpool_runtime
();
let
r
=
rt
.block_on
(
future
);
sender
.send
(
r
)
.unwrap
();
let
r
=
match
create_threadpool_runtime
()
{
Ok
(
mut
rt
)
=>
rt
.block_on
(
future
),
Err
(
e
)
=>
Err
(
ErrBox
::
from
(
e
)),
};
sender
.send
(
r
)
.expect
(
"Unable to send blocking future result"
)
});
receiver
.recv
()
.unwrap
()
receiver
.recv
()
.expect
(
"Unable to receive blocking future result"
)
}
// Set the default executor so we can use tokio::spawn(). It's difficult to
...
...
@@ -65,7 +71,7 @@ pub fn init<F>(f: F)
where
F
:
FnOnce
(),
{
let
rt
=
create_threadpool_runtime
();
let
rt
=
create_threadpool_runtime
()
.expect
(
"Unable to create Tokio runtime"
)
;
let
mut
executor
=
rt
.executor
();
let
mut
enter
=
tokio_executor
::
enter
()
.expect
(
"Multiple executors at once"
);
tokio_executor
::
with_default
(
&
mut
executor
,
&
mut
enter
,
move
|
_
enter
|
f
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录