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
|
|
@ -1,7 +1,6 @@
|
|||
mod ae_fd;
|
||||
mod ae_queue;
|
||||
mod ae_task;
|
||||
mod ae_timeout;
|
||||
mod ae_timer;
|
||||
mod ae_yield;
|
||||
|
||||
|
|
@ -9,18 +8,15 @@ pub use {
|
|||
crate::async_engine::ae_yield::Yield,
|
||||
ae_fd::{AsyncFd, FdStatus},
|
||||
ae_task::SpawnedFuture,
|
||||
ae_timeout::Timeout,
|
||||
ae_timer::Timer,
|
||||
};
|
||||
use {
|
||||
crate::{
|
||||
event_loop::{EventLoop, EventLoopError},
|
||||
utils::{copyhashmap::CopyHashMap, numcell::NumCell, oserror::OsError},
|
||||
wheel::{Wheel, WheelError},
|
||||
},
|
||||
ae_fd::AsyncFdData,
|
||||
ae_queue::{DispatchQueue, Dispatcher},
|
||||
ae_timeout::TimeoutData,
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
future::Future,
|
||||
|
|
@ -32,8 +28,6 @@ use {
|
|||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AsyncError {
|
||||
#[error("The timer wheel returned an error")]
|
||||
WheelError(#[from] WheelError),
|
||||
#[error("The event loop caused an error")]
|
||||
EventLoopError(#[from] EventLoopError),
|
||||
#[error("Could not read from a timer")]
|
||||
|
|
@ -54,37 +48,21 @@ pub enum Phase {
|
|||
const NUM_PHASES: usize = 4;
|
||||
|
||||
pub struct AsyncEngine {
|
||||
wheel: Rc<Wheel>,
|
||||
el: Rc<EventLoop>,
|
||||
queue: Rc<DispatchQueue>,
|
||||
fds: CopyHashMap<i32, Rc<AsyncFdData>>,
|
||||
}
|
||||
|
||||
impl AsyncEngine {
|
||||
pub fn install(el: &Rc<EventLoop>, wheel: &Rc<Wheel>) -> Result<Rc<Self>, AsyncError> {
|
||||
pub fn install(el: &Rc<EventLoop>) -> Result<Rc<Self>, AsyncError> {
|
||||
let queue = Dispatcher::install(el)?;
|
||||
Ok(Rc::new(Self {
|
||||
wheel: wheel.clone(),
|
||||
el: el.clone(),
|
||||
queue,
|
||||
fds: CopyHashMap::new(),
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn timeout(&self, ms: u64) -> Result<Timeout, AsyncError> {
|
||||
let data = Rc::new(TimeoutData {
|
||||
expired: Cell::new(false),
|
||||
waker: RefCell::new(None),
|
||||
});
|
||||
let id = self.wheel.id();
|
||||
self.wheel.timeout(id, ms, data.clone())?;
|
||||
Ok(Timeout {
|
||||
id,
|
||||
wheel: self.wheel.clone(),
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn timer(self: &Rc<Self>, clock_id: c::c_int) -> Result<Timer, AsyncError> {
|
||||
Timer::new(self, clock_id)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue