async: rebase wheel on top of async engine
This commit is contained in:
parent
87a90a8ae4
commit
3875c63172
13 changed files with 218 additions and 285 deletions
|
|
@ -146,10 +146,6 @@ impl AsyncFd {
|
|||
self.data.fd.raw()
|
||||
}
|
||||
|
||||
pub fn eng(&self) -> &Rc<AsyncEngine> {
|
||||
&self.engine
|
||||
}
|
||||
|
||||
pub fn readable(&self) -> AsyncFdReadable {
|
||||
AsyncFdReadable {
|
||||
fd: self,
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
use {
|
||||
crate::wheel::{Wheel, WheelDispatcher, WheelId},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
error::Error,
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
rc::Rc,
|
||||
task::{Context, Poll, Waker},
|
||||
},
|
||||
};
|
||||
|
||||
pub(super) struct TimeoutData {
|
||||
pub expired: Cell<bool>,
|
||||
pub waker: RefCell<Option<Waker>>,
|
||||
}
|
||||
|
||||
impl WheelDispatcher for TimeoutData {
|
||||
fn dispatch(self: Rc<Self>) -> Result<(), Box<dyn Error>> {
|
||||
self.expired.set(true);
|
||||
if let Some(w) = self.waker.borrow_mut().take() {
|
||||
w.wake();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Timeout {
|
||||
pub(super) id: WheelId,
|
||||
pub(super) wheel: Rc<Wheel>,
|
||||
pub(super) data: Rc<TimeoutData>,
|
||||
}
|
||||
|
||||
impl Future for Timeout {
|
||||
type Output = ();
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
if self.data.expired.get() {
|
||||
Poll::Ready(())
|
||||
} else {
|
||||
*self.data.waker.borrow_mut() = Some(cx.waker().clone());
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Timeout {
|
||||
fn drop(&mut self) {
|
||||
self.wheel.remove(self.id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue