Basic queue test
This commit is contained in:
parent
75092669b4
commit
d05e7e031b
14
src/queue.rs
14
src/queue.rs
@ -229,3 +229,17 @@ impl Drop for BlockQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use util::*;
|
||||||
|
use spec::*;
|
||||||
|
use queue::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_block_queue() {
|
||||||
|
// TODO better test
|
||||||
|
let spec = Spec::new_test();
|
||||||
|
let engine = spec.to_engine().unwrap();
|
||||||
|
let _ = BlockQueue::new(Arc::new(engine), IoChannel::disconnected());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -151,14 +151,22 @@ impl<Message> Handler for IoManager<Message> where Message: Send + 'static {
|
|||||||
/// Allows sending messages into the event loop. All the IO handlers will get the message
|
/// Allows sending messages into the event loop. All the IO handlers will get the message
|
||||||
/// in the `message` callback.
|
/// in the `message` callback.
|
||||||
pub struct IoChannel<Message> where Message: Send {
|
pub struct IoChannel<Message> where Message: Send {
|
||||||
channel: Sender<IoMessage<Message>>
|
channel: Option<Sender<IoMessage<Message>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message> IoChannel<Message> where Message: Send {
|
impl<Message> IoChannel<Message> where Message: Send {
|
||||||
|
/// Send a msessage through the channel
|
||||||
pub fn send(&self, message: Message) -> Result<(), IoError> {
|
pub fn send(&self, message: Message) -> Result<(), IoError> {
|
||||||
try!(self.channel.send(IoMessage::UserMessage(message)));
|
if let Some(ref channel) = self.channel {
|
||||||
|
try!(channel.send(IoMessage::UserMessage(message)));
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new channel to connected to event loop.
|
||||||
|
pub fn disconnected() -> IoChannel<Message> {
|
||||||
|
IoChannel { channel: None }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// General IO Service. Starts an event loop and dispatches IO requests.
|
/// General IO Service. Starts an event loop and dispatches IO requests.
|
||||||
@ -198,7 +206,7 @@ impl<Message> IoService<Message> where Message: Send + 'static {
|
|||||||
|
|
||||||
/// Create a new message channel
|
/// Create a new message channel
|
||||||
pub fn channel(&mut self) -> IoChannel<Message> {
|
pub fn channel(&mut self) -> IoChannel<Message> {
|
||||||
IoChannel { channel: self.host_channel.clone() }
|
IoChannel { channel: Some(self.host_channel.clone()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user