Skip to content

Commit f20dea2

Browse files
committed
prepare for capnp-futures-v0.15.1 release
1 parent b5d52dd commit f20dea2

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

capnp-futures/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v0.15.1
2+
- Fill in unimiplemented len() method of write_queue::Sender.
3+
- Add is_empty() method to write_queue::Sender.
4+
- Apply a bunch of formatting and style fixes that should have no observable effects.
5+
16
## v0.15.0
27
- Follow v0.15.0 release of other capnp crates.
38

capnp-futures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "capnp-futures"
3-
version = "0.15.0"
3+
version = "0.15.1"
44
authors = [ "David Renshaw <drenshaw@gmail.com>" ]
55
license = "MIT"
66

capnp-futures/src/write_queue.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ where
3333
Message(M, oneshot::Sender<M>),
3434
Done(Result<(), Error>, oneshot::Sender<()>),
3535
}
36-
/// A handle that allows message to be sent to a write queue`.
36+
/// A handle that allows messages to be sent to a write queue.
3737
pub struct Sender<M>
3838
where
3939
M: AsOutputSegments,
4040
{
4141
sender: futures::channel::mpsc::UnboundedSender<Item<M>>,
42+
in_flight: std::sync::Arc<std::sync::atomic::AtomicI32>,
4243
}
4344

4445
impl<M> Clone for Sender<M>
@@ -48,25 +49,33 @@ where
4849
fn clone(&self) -> Self {
4950
Self {
5051
sender: self.sender.clone(),
52+
in_flight: self.in_flight.clone(),
5153
}
5254
}
5355
}
5456

55-
/// Creates a new WriteQueue that wraps the given writer.
57+
/// Creates a new write queue that wraps the given `AsyncWrite`.
5658
pub fn write_queue<W, M>(mut writer: W) -> (Sender<M>, impl Future<Output = Result<(), Error>>)
5759
where
5860
W: AsyncWrite + Unpin,
5961
M: AsOutputSegments,
6062
{
6163
let (tx, mut rx) = futures::channel::mpsc::unbounded();
6264

63-
let sender = Sender { sender: tx };
65+
let in_flight = std::sync::Arc::new(std::sync::atomic::AtomicI32::new(0));
66+
67+
let sender = Sender {
68+
sender: tx,
69+
in_flight: in_flight.clone(),
70+
};
6471

6572
let queue = async move {
6673
while let Some(item) = rx.next().await {
6774
match item {
6875
Item::Message(m, returner) => {
69-
crate::serialize::write_message(&mut writer, &m).await?;
76+
let result = crate::serialize::write_message(&mut writer, &m).await;
77+
in_flight.fetch_sub(1, std::sync::atomic::Ordering::SeqCst);
78+
result?;
7079
writer.flush().await?;
7180
let _ = returner.send(m);
7281
}
@@ -96,12 +105,14 @@ where
96105
oneshot.map_err(|oneshot::Canceled| Error::disconnected("WriteQueue has terminated".into()))
97106
}
98107

99-
/// Returns the number of messages queued to be written, not including any in-progress write.
100-
pub fn len(&mut self) -> usize {
101-
unimplemented!()
108+
/// Returns the number of messages queued to be written.
109+
pub fn len(&self) -> usize {
110+
let result = self.in_flight.load(std::sync::atomic::Ordering::SeqCst);
111+
assert!(result >= 0);
112+
result as usize
102113
}
103114

104-
pub fn is_empty(&mut self) -> bool {
115+
pub fn is_empty(&self) -> bool {
105116
self.len() == 0
106117
}
107118

0 commit comments

Comments
 (0)