Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabc2929

Browse files
committed
switch to async-executor
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
1 parent0c51283 commitabc2929

File tree

5 files changed

+18
-37
lines changed

5 files changed

+18
-37
lines changed

‎Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
2424
[features]
2525
default = [
2626
"std",
27+
"async-executor",
2728
"async-io",
2829
"async-task",
2930
"blocking",
3031
"futures-lite",
3132
"kv-log-macro",
3233
"log",
33-
"multitask",
3434
"num_cpus",
3535
"pin-project-lite",
3636
]
@@ -80,10 +80,10 @@ futures-timer = { version = "3.0.2", optional = true }
8080
surf = {version ="1.0.3",optional =true }
8181

8282
[target.'cfg(not(target_os="unknown"))'.dependencies]
83+
async-executor = {version ="0.1.1",features = ["async-io"],optional =true }
8384
async-io = {version ="0.1.5",optional =true }
8485
blocking = {version ="0.5.0",optional =true }
8586
futures-lite = {version ="0.1.8",optional =true }
86-
multitask = {version ="0.2.0",optional =true }
8787

8888
[target.'cfg(target_arch="wasm32")'.dependencies]
8989
futures-timer = {version ="3.0.2",optional =true,features = ["wasm-bindgen"] }

‎src/rt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
2727
for _in0..thread_count{
2828
thread::Builder::new()
2929
.name(thread_name.clone())
30-
.spawn(||crate::task::block_on(future::pending::<()>()))
30+
.spawn(||crate::task::executor::run_global(future::pending::<()>()))
3131
.expect("cannot start a runtime thread");
3232
}
3333
Runtime{}

‎src/task/executor.rs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
use std::cell::RefCell;
22
use std::future::Future;
3-
use std::task::{Context,Poll};
43

5-
staticGLOBAL_EXECUTOR: once_cell::sync::Lazy<multitask::Executor> = once_cell::sync::Lazy::new(multitask::Executor::new);
6-
7-
structExecutor{
8-
local_executor: multitask::LocalExecutor,
9-
parker: async_io::parking::Parker,
10-
}
4+
staticGLOBAL_EXECUTOR: once_cell::sync::Lazy<async_executor::Executor> = once_cell::sync::Lazy::new(async_executor::Executor::new);
115

126
thread_local!{
13-
staticEXECUTOR:RefCell<Executor> =RefCell::new({
14-
let(parker, unparker) = async_io::parking::pair();
15-
let local_executor = multitask::LocalExecutor::new(move || unparker.unpark());
16-
Executor{ local_executor, parker}
17-
});
7+
staticEXECUTOR:RefCell<async_executor::LocalExecutor> =RefCell::new(async_executor::LocalExecutor::new());
188
}
199

20-
pub(crate)fnspawn<F,T>(future:F) ->multitask::Task<T>
10+
pub(crate)fnspawn<F,T>(future:F) ->async_executor::Task<T>
2111
where
2212
F:Future<Output =T> +Send +'static,
2313
T:Send +'static,
@@ -26,35 +16,26 @@ where
2616
}
2717

2818
#[cfg(feature ="unstable")]
29-
pub(crate)fnlocal<F,T>(future:F) ->multitask::Task<T>
19+
pub(crate)fnlocal<F,T>(future:F) ->async_executor::Task<T>
3020
where
3121
F:Future<Output =T> +'static,
3222
T:'static,
3323
{
34-
EXECUTOR.with(|executor| executor.borrow().local_executor.spawn(future))
24+
EXECUTOR.with(|executor| executor.borrow().spawn(future))
3525
}
3626

3727
pub(crate)fnrun<F,T>(future:F) ->T
3828
where
3929
F:Future<Output =T>,
4030
{
41-
enter(||EXECUTOR.with(|executor|{
42-
let executor = executor.borrow();
43-
let unparker = executor.parker.unparker();
44-
let global_ticker =GLOBAL_EXECUTOR.ticker(move || unparker.unpark());
45-
let unparker = executor.parker.unparker();
46-
let waker = async_task::waker_fn(move || unparker.unpark());
47-
let cx =&mutContext::from_waker(&waker);
48-
pin_utils::pin_mut!(future);
49-
loop{
50-
ifletPoll::Ready(res) = future.as_mut().poll(cx){
51-
return res;
52-
}
53-
ifletOk(false) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| executor.local_executor.tick() || global_ticker.tick())){
54-
executor.parker.park();
55-
}
56-
}
57-
}))
31+
EXECUTOR.with(|executor|enter(||GLOBAL_EXECUTOR.enter(|| executor.borrow().run(future))))
32+
}
33+
34+
pub(crate)fnrun_global<F,T>(future:F) ->T
35+
where
36+
F:Future<Output =T>,
37+
{
38+
enter(||GLOBAL_EXECUTOR.run(future))
5839
}
5940

6041
/// Enters the tokio context if the `tokio` feature is enabled.

‎src/task/join_handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct JoinHandle<T> {
1818
}
1919

2020
#[cfg(not(target_os ="unknown"))]
21-
typeInnerHandle<T> =multitask::Task<T>;
21+
typeInnerHandle<T> =async_executor::Task<T>;
2222
#[cfg(target_arch ="wasm32")]
2323
typeInnerHandle<T> = futures_channel::oneshot::Receiver<T>;
2424

‎src/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ cfg_default! {
149149
mod builder;
150150
mod current;
151151
#[cfg(not(target_os ="unknown"))]
152-
mod executor;
152+
pub(crate)mod executor;
153153
mod join_handle;
154154
mod sleep;
155155
#[cfg(not(target_os ="unknown"))]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp