Basic queue test

This commit is contained in:
arkpar 2016-01-18 00:24:20 +01:00
parent 75092669b4
commit d05e7e031b
2 changed files with 25 additions and 3 deletions

View File

@ -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());
}
}

View File

@ -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
/// in the `message` callback.
pub struct IoChannel<Message> where Message: Send {
channel: Sender<IoMessage<Message>>
channel: Option<Sender<IoMessage<Message>>>
}
impl<Message> IoChannel<Message> where Message: Send {
/// Send a msessage through the channel
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(())
}
/// 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.
@ -198,7 +206,7 @@ impl<Message> IoService<Message> where Message: Send + 'static {
/// Create a new message channel
pub fn channel(&mut self) -> IoChannel<Message> {
IoChannel { channel: self.host_channel.clone() }
IoChannel { channel: Some(self.host_channel.clone()) }
}
}