Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
25b13c89
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,发现更多精彩内容 >>
未验证
提交
25b13c89
编写于
1月 30, 2020
作者:
R
Ryan Dahl
提交者:
GitHub
1月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use tokio::main (#3831)
上级
2338e767
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
105 deletion
+82
-105
cli/lib.rs
cli/lib.rs
+79
-100
cli/tokio_util.rs
cli/tokio_util.rs
+3
-5
未找到文件。
cli/lib.rs
浏览文件 @
25b13c89
...
...
@@ -256,7 +256,7 @@ async fn print_file_info(
}
}
fn
info_command
(
flags
:
DenoFlags
)
{
async
fn
info_command
(
flags
:
DenoFlags
)
{
let
argv_len
=
flags
.argv
.len
();
let
(
mut
worker
,
state
)
=
create_worker_and_state
(
flags
);
...
...
@@ -271,20 +271,16 @@ fn info_command(flags: DenoFlags) {
js_check
(
worker
.execute
(
"bootstrapMainRuntime()"
));
debug!
(
"main_module {}"
,
main_module
);
let
main_future
=
async
move
{
let
main_result
=
worker
.execute_mod_async
(
&
main_module
,
None
,
true
)
.await
;
if
let
Err
(
e
)
=
main_result
{
print_err_and_exit
(
e
);
}
print_file_info
(
worker
.clone
(),
main_module
.clone
())
.await
;
let
result
=
worker
.await
;
js_check
(
result
);
};
tokio_util
::
run
(
main_future
);
let
main_result
=
worker
.execute_mod_async
(
&
main_module
,
None
,
true
)
.await
;
if
let
Err
(
e
)
=
main_result
{
print_err_and_exit
(
e
);
}
print_file_info
(
worker
.clone
(),
main_module
.clone
())
.await
;
let
result
=
worker
.await
;
js_check
(
result
);
}
fn
fetch_command
(
flags
:
DenoFlags
)
{
async
fn
fetch_command
(
flags
:
DenoFlags
)
{
let
(
mut
worker
,
state
)
=
create_worker_and_state
(
flags
);
let
main_module
=
state
.main_module
.as_ref
()
.unwrap
()
.clone
();
...
...
@@ -293,26 +289,22 @@ fn fetch_command(flags: DenoFlags) {
js_check
(
worker
.execute
(
"bootstrapMainRuntime()"
));
debug!
(
"main_module {}"
,
main_module
);
let
main_future
=
async
move
{
let
result
=
worker
.execute_mod_async
(
&
main_module
,
None
,
true
)
.await
;
js_check
(
result
);
if
state
.flags.lock_write
{
if
let
Some
(
ref
lockfile
)
=
state
.lockfile
{
let
g
=
lockfile
.lock
()
.unwrap
();
if
let
Err
(
e
)
=
g
.write
()
{
print_err_and_exit
(
ErrBox
::
from
(
e
));
}
}
else
{
eprintln!
(
"--lock flag must be specified when using --lock-write"
);
std
::
process
::
exit
(
11
);
let
result
=
worker
.execute_mod_async
(
&
main_module
,
None
,
true
)
.await
;
js_check
(
result
);
if
state
.flags.lock_write
{
if
let
Some
(
ref
lockfile
)
=
state
.lockfile
{
let
g
=
lockfile
.lock
()
.unwrap
();
if
let
Err
(
e
)
=
g
.write
()
{
print_err_and_exit
(
ErrBox
::
from
(
e
));
}
}
else
{
eprintln!
(
"--lock flag must be specified when using --lock-write"
);
std
::
process
::
exit
(
11
);
}
};
tokio_util
::
run
(
main_future
);
}
}
fn
eval_command
(
flags
:
DenoFlags
)
{
async
fn
eval_command
(
flags
:
DenoFlags
)
{
let
ts_source
=
flags
.argv
[
1
]
.clone
();
let
(
mut
worker
,
_
state
)
=
create_worker_and_state
(
flags
);
// Force TypeScript compile.
...
...
@@ -322,62 +314,52 @@ fn eval_command(flags: DenoFlags) {
js_check
(
worker
.execute
(
"bootstrapMainRuntime()"
));
debug!
(
"main_module {}"
,
&
main_module
);
let
main_future
=
async
move
{
let
exec_result
=
worker
.execute_mod_async
(
&
main_module
,
Some
(
ts_source
),
false
)
.await
;
if
let
Err
(
e
)
=
exec_result
{
print_err_and_exit
(
e
);
}
js_check
(
worker
.execute
(
"window.dispatchEvent(new Event('load'))"
));
let
mut
worker_
=
worker
.clone
();
let
result
=
worker
.await
;
js_check
(
result
);
js_check
(
worker_
.execute
(
"window.dispatchEvent(new Event('unload'))"
));
};
tokio_util
::
run
(
main_future
);
let
exec_result
=
worker
.execute_mod_async
(
&
main_module
,
Some
(
ts_source
),
false
)
.await
;
if
let
Err
(
e
)
=
exec_result
{
print_err_and_exit
(
e
);
}
js_check
(
worker
.execute
(
"window.dispatchEvent(new Event('load'))"
));
let
mut
worker_
=
worker
.clone
();
let
result
=
worker
.await
;
js_check
(
result
);
js_check
(
worker_
.execute
(
"window.dispatchEvent(new Event('unload'))"
));
}
fn
bundle_command
(
flags
:
DenoFlags
)
{
async
fn
bundle_command
(
flags
:
DenoFlags
)
{
let
out_file
=
flags
.bundle_output
.clone
();
let
(
worker
,
state
)
=
create_worker_and_state
(
flags
);
let
main_module
=
state
.main_module
.as_ref
()
.unwrap
()
.clone
();
debug!
(
">>>>> bundle_async START"
);
// NOTE: we need to poll `worker` otherwise TS compiler worker won't run properly
let
main_future
=
async
move
{
let
result
=
worker
.await
;
js_check
(
result
);
let
bundle_result
=
state
.ts_compiler
.bundle_async
(
state
.clone
(),
main_module
.to_string
(),
out_file
)
.await
;
if
let
Err
(
err
)
=
bundle_result
{
debug!
(
"diagnostics returned, exiting!"
);
eprintln!
(
""
);
print_err_and_exit
(
err
);
}
debug!
(
">>>>> bundle_async END"
);
};
tokio_util
::
run
(
main_future
);
let
result
=
worker
.await
;
js_check
(
result
);
let
bundle_result
=
state
.ts_compiler
.bundle_async
(
state
.clone
(),
main_module
.to_string
(),
out_file
)
.await
;
if
let
Err
(
err
)
=
bundle_result
{
debug!
(
"diagnostics returned, exiting!"
);
eprintln!
(
""
);
print_err_and_exit
(
err
);
}
debug!
(
">>>>> bundle_async END"
);
}
fn
run_repl
(
flags
:
DenoFlags
)
{
async
fn
run_repl
(
flags
:
DenoFlags
)
{
let
(
mut
worker
,
_
state
)
=
create_worker_and_state
(
flags
);
js_check
(
worker
.execute
(
"bootstrapMainRuntime()"
));
let
main_future
=
async
move
{
loop
{
let
result
=
worker
.clone
()
.await
;
if
let
Err
(
err
)
=
result
{
eprintln!
(
"{}"
,
err
.to_string
());
}
loop
{
let
result
=
worker
.clone
()
.await
;
if
let
Err
(
err
)
=
result
{
eprintln!
(
"{}"
,
err
.to_string
());
}
};
tokio_util
::
run
(
main_future
);
}
}
fn
run_script
(
flags
:
DenoFlags
)
{
async
fn
run_script
(
flags
:
DenoFlags
)
{
let
(
mut
worker
,
state
)
=
create_worker_and_state
(
flags
);
let
maybe_main_module
=
state
.main_module
.as_ref
();
...
...
@@ -393,36 +375,33 @@ fn run_script(flags: DenoFlags) {
let
mut
worker_
=
worker
.clone
();
let
main_future
=
async
move
{
let
mod_result
=
worker
.execute_mod_async
(
&
main_module
,
None
,
false
)
.await
;
if
let
Err
(
err
)
=
mod_result
{
print_err_and_exit
(
err
);
}
if
state
.flags.lock_write
{
if
let
Some
(
ref
lockfile
)
=
state
.lockfile
{
let
g
=
lockfile
.lock
()
.unwrap
();
if
let
Err
(
e
)
=
g
.write
()
{
print_err_and_exit
(
ErrBox
::
from
(
e
));
}
}
else
{
eprintln!
(
"--lock flag must be specified when using --lock-write"
);
std
::
process
::
exit
(
11
);
let
mod_result
=
worker
.execute_mod_async
(
&
main_module
,
None
,
false
)
.await
;
if
let
Err
(
err
)
=
mod_result
{
print_err_and_exit
(
err
);
}
if
state
.flags.lock_write
{
if
let
Some
(
ref
lockfile
)
=
state
.lockfile
{
let
g
=
lockfile
.lock
()
.unwrap
();
if
let
Err
(
e
)
=
g
.write
()
{
print_err_and_exit
(
ErrBox
::
from
(
e
));
}
}
else
{
eprintln!
(
"--lock flag must be specified when using --lock-write"
);
std
::
process
::
exit
(
11
);
}
js_check
(
worker
.execute
(
"window.dispatchEvent(new Event('load'))"
));
let
result
=
worker
.await
;
js_check
(
result
);
js_check
(
worker_
.execute
(
"window.dispatchEvent(new Event('unload'))"
));
};
tokio_util
::
run
(
main_future
);
}
js_check
(
worker
.execute
(
"window.dispatchEvent(new Event('load'))"
));
let
result
=
worker
.await
;
js_check
(
result
);
js_check
(
worker_
.execute
(
"window.dispatchEvent(new Event('unload'))"
));
}
fn
forma
t_command
(
files
:
Option
<
Vec
<
String
>>
,
check
:
bool
)
{
async
fn
fm
t_command
(
files
:
Option
<
Vec
<
String
>>
,
check
:
bool
)
{
fmt
::
format_files
(
files
,
check
);
}
pub
fn
main
()
{
#[tokio::main]
pub
async
fn
main
()
{
#[cfg(windows)]
ansi_term
::
enable_ansi_support
()
.ok
();
// For Windows 10
...
...
@@ -443,14 +422,14 @@ pub fn main() {
log
::
set_max_level
(
log_level
.to_level_filter
());
match
flags
.clone
()
.subcommand
{
DenoSubcommand
::
Bundle
=>
bundle_command
(
flags
),
DenoSubcommand
::
Bundle
=>
bundle_command
(
flags
)
.await
,
DenoSubcommand
::
Completions
=>
{}
DenoSubcommand
::
Eval
=>
eval_command
(
flags
),
DenoSubcommand
::
Fetch
=>
fetch_command
(
flags
),
DenoSubcommand
::
Format
{
check
,
files
}
=>
f
ormat_command
(
files
,
check
)
,
DenoSubcommand
::
Info
=>
info_command
(
flags
),
DenoSubcommand
::
Repl
=>
run_repl
(
flags
),
DenoSubcommand
::
Run
=>
run_script
(
flags
),
DenoSubcommand
::
Eval
=>
eval_command
(
flags
)
.await
,
DenoSubcommand
::
Fetch
=>
fetch_command
(
flags
)
.await
,
DenoSubcommand
::
Format
{
check
,
files
}
=>
f
mt_command
(
files
,
check
)
.await
,
DenoSubcommand
::
Info
=>
info_command
(
flags
)
.await
,
DenoSubcommand
::
Repl
=>
run_repl
(
flags
)
.await
,
DenoSubcommand
::
Run
=>
run_script
(
flags
)
.await
,
DenoSubcommand
::
Types
=>
types_command
(),
_
=>
panic!
(
"bad subcommand"
),
}
...
...
cli/tokio_util.rs
浏览文件 @
25b13c89
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use
std
::
future
::
Future
;
use
tokio
;
use
tokio
::
runtime
;
#[cfg(test)]
pub
fn
run
<
F
>
(
future
:
F
)
where
F
:
Future
<
Output
=
()
>
+
Send
+
'static
,
F
:
std
::
future
::
Future
<
Output
=
()
>
+
Send
+
'static
,
{
let
mut
rt
=
runtime
::
Builder
::
new
()
let
mut
rt
=
tokio
::
runtime
::
Builder
::
new
()
.threaded_scheduler
()
.enable_all
()
.thread_name
(
"deno"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录