mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Add test-only MessageQueue::subscribe_any.
This makes writing tests that do async things easier.
This commit is contained in:
@@ -61,6 +61,7 @@ impl<T: Clone> MessageQueue<T> {
|
||||
mem::replace::<Vec<_>>(&mut message_listeners, remaining_listeners);
|
||||
}
|
||||
|
||||
/// Subscribe to any messages occurring after the given message cursor.
|
||||
pub fn subscribe(&self, cursor: u32, sender: oneshot::Sender<(u32, Vec<T>)>) {
|
||||
let listener = {
|
||||
let listener = Listener { sender, cursor };
|
||||
@@ -77,6 +78,22 @@ impl<T: Clone> MessageQueue<T> {
|
||||
message_listeners.push(listener);
|
||||
}
|
||||
|
||||
/// Subscribe to any messages being pushed into the queue.
|
||||
///
|
||||
/// This method is only useful in tests. Non-test code should use subscribe
|
||||
/// instead.
|
||||
#[cfg(test)]
|
||||
pub fn subscribe_any(&self) -> oneshot::Receiver<(u32, Vec<T>)> {
|
||||
let cursor = {
|
||||
let messages = self.messages.read().unwrap();
|
||||
messages.len() as u32
|
||||
};
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
|
||||
self.subscribe(cursor, sender);
|
||||
receiver
|
||||
}
|
||||
|
||||
pub fn cursor(&self) -> u32 {
|
||||
self.messages.read().unwrap().len() as u32
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user