Skip to content

Instantly share code, notes, and snippets.

@azriel91
Created April 14, 2017 02:56
Show Gist options
  • Save azriel91/e0084994eb99d84c1ca0a79f1a913bf3 to your computer and use it in GitHub Desktop.
Save azriel91/e0084994eb99d84c1ca0a79f1a913bf3 to your computer and use it in GitHub Desktop.
let mut collection_buffer = Vec::with_capacity(input_buffer.len());
let mut input_iter = input_buffer.drain(..);
loop {
if let Some(input) = input_iter.next() {
let result = context.as_ref()
.unwrap()
.listener_tx
.send(input);
// if we fail to send, it implies the listener has stopped listening
// we then buffer all of the input for the next activity
if let Err(SendError(missed_input)) = result {
collection_buffer.push(missed_input);
while let Some(input) = input_iter.next() {
collection_buffer.push(input);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment