Skip to content

Commit 967aef3

Browse files
committed
refactor(executor): move Task::poll to impl Future
1 parent f677947 commit 967aef3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/executor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) mod vsock;
99
use alloc::sync::Arc;
1010
use alloc::task::Wake;
1111
use core::future::Future;
12-
use core::pin::pin;
12+
use core::pin::{Pin, pin};
1313
use core::sync::atomic::AtomicU32;
1414
use core::task::{Context, Poll, Waker};
1515
use core::time::Duration;
@@ -102,7 +102,7 @@ pub(crate) fn run() {
102102
let mut task = { core_local::async_tasks().pop_front().unwrap() };
103103
trace!("Run async task {}", task.id());
104104

105-
if task.poll(&mut cx).is_pending() {
105+
if Pin::new(&mut task).poll(&mut cx).is_pending() {
106106
core_local::async_tasks().push_back(task);
107107
}
108108
}

src/executor/task.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ impl AsyncTask {
3939
pub fn id(&self) -> AsyncTaskId {
4040
self.id
4141
}
42+
}
43+
44+
impl Future for AsyncTask {
45+
type Output = ();
4246

43-
pub fn poll(&mut self, context: &mut Context<'_>) -> Poll<()> {
44-
self.future.as_mut().poll(context)
47+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
48+
self.as_mut().future.as_mut().poll(cx)
4549
}
4650
}

0 commit comments

Comments
 (0)