Skip to content

Commit

Permalink
Merge pull request #19 from halzy/halzy/17-values
Browse files Browse the repository at this point in the history
feat!: #17 renamed OutgoingMessage.value to values
  • Loading branch information
halzy authored Mar 2, 2020
2 parents 4e2b3d2 + 1e2f48f commit 9e07584
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stream_multiplexer"
version = "0.7.0"
version = "0.8.0"
authors = ["Benjamin Halsted <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,18 @@ impl<V> std::fmt::Debug for IncomingPacket<V> {
/// The payload of an OutgoingPacket
#[derive(Clone)]
pub struct OutgoingMessage<V> {
stream_ids: Vec<StreamId>,
value: tinyvec::TinyVec<[Option<V>; 16]>,
stream_ids: tinyvec::TinyVec<[Option<StreamId>; 16]>,
values: tinyvec::TinyVec<[Option<V>; 16]>,
}
impl<V> OutgoingMessage<V> {
/// Creates a new message that is to be delivered to streams with `ids`.
pub fn new(stream_ids: Vec<StreamId>, values: impl IntoIterator<Item = V>) -> Self {
pub fn new(
stream_ids: impl IntoIterator<Item = StreamId>,
values: impl IntoIterator<Item = V>,
) -> Self {
let stream_ids = tinyvec::TinyVec::from_iter(stream_ids.into_iter().map(Some));
let values = tinyvec::TinyVec::from_iter(values.into_iter().map(Some));
Self {
stream_ids,
value: values,
}
Self { stream_ids, values }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/multiplexer_senders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ where
}

fn handle_new_message(&mut self, mut message: OutgoingMessage<Item>) {
for stream_id in message.stream_ids {
for stream_id in message.stream_ids.iter().cloned().flatten() {
match self.sender_pairs.entry(stream_id) {
Entry::Vacant(_) => {
tracing::warn!(stream_id, "Tring to send message to non-existent stream.");
}
Entry::Occupied(mut sender_pair_entry) => {
let mut should_remove = false;
for value in message.value.drain(..).flatten() {
for value in message.values.drain(..).flatten() {
let sender_pair = sender_pair_entry.get_mut();
match sender_pair.try_send(value.clone()) {
Ok(()) => {
Expand Down

0 comments on commit 9e07584

Please sign in to comment.