asyncio/async/
mod.rs

1use error::ErrCode;
2use core::{IoContext, ThreadIoContext, Upcast, FnOp};
3
4pub trait Sender<R, E, G: WrappedHandler<R, E>> : FnOp + Upcast<FnOp + Send> {
5    fn send(self: Box<Self>, &IoContext, Result<R, E>);
6
7    fn as_self(&self) -> &G;
8
9    fn as_mut_self(&mut self) -> &mut G;
10}
11
12impl<R, E, G> Into<Box<FnOp + Send>> for Box<Sender<R, E, G> + Send> {
13    fn into(self) -> Box<FnOp + Send> {
14        self.upcast()
15    }
16}
17
18pub type Operation<R, E, G> = Box<Sender<R, E, G> + Send>;
19
20pub trait Receiver<R> {
21    fn recv(self, &IoContext) -> R;
22}
23
24pub struct NullReceiver;
25
26impl Receiver<()> for NullReceiver {
27    fn recv(self, _: &IoContext) {
28    }
29}
30
31pub trait WrappedHandler<R, E> {
32    fn perform(&mut self, &IoContext, &mut ThreadIoContext, ErrCode, Operation<R, E, Self>);
33}
34
35pub trait Handler<R, E> : Sized {
36    type Output;
37
38    fn result(self, &IoContext, Result<R, E>) -> Self::Output;
39
40    #[doc(hidden)]
41    type Receiver : Receiver<Self::Output>;
42
43    #[doc(hidden)]
44    fn channel<G>(self, G) -> (Operation<R, E, G>, Self::Receiver)
45        where G: WrappedHandler<R, E> + Send + 'static;
46}
47
48mod wrap;
49pub use self::wrap::{wrap};
50
51mod strand;
52pub use self::strand::{Strand, StrandImmutable};
53
54#[cfg(feature = "context")] mod coroutine;
55#[cfg(feature = "context")] pub use self::coroutine::{Coroutine};