Skip to content

Commit 5cfa204

Browse files
committed
rename crate, adapter and extension method to FutureQueue
We're going to add a FutureQueueGrouped to this crate. `buffer_unordered_weighted` is a bit too heady a name, and `future_queue` describes what the crate does rather than how it's implemented.
1 parent 97062ce commit 5cfa204

File tree

10 files changed

+67
-64
lines changed

10 files changed

+67
-64
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: taiki-e/create-gh-release-action@v1
2323
with:
2424
changelog: CHANGELOG.md
25-
title: buffer-unordered-weighted $version
25+
title: future-queue $version
2626
branch: main
2727
env:
2828
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
- Initial release.
1414

15-
[0.1.2]: https://github.com/nextest-rs/buffer-unordered-weighted/releases/tag/0.1.2
16-
[0.1.1]: https://github.com/nextest-rs/buffer-unordered-weighted/releases/tag/0.1.1
17-
[0.1.0]: https://github.com/nextest-rs/buffer-unordered-weighted/releases/tag/0.1.0
15+
[0.1.2]: https://github.com/nextest-rs/future-queue/releases/tag/0.1.2
16+
[0.1.1]: https://github.com/nextest-rs/future-queue/releases/tag/0.1.1
17+
[0.1.0]: https://github.com/nextest-rs/future-queue/releases/tag/0.1.0

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ able to be built and passes all checks performed by CI.
2828

2929
## License
3030

31-
By contributing to `buffer-unordered-weighted`, you agree that your contributions will be
31+
By contributing to `future-queue`, you agree that your contributions will be
3232
dual-licensed under the terms of the [`LICENSE-MIT`](LICENSE-MIT) and
3333
[`LICENSE-APACHE`](LICENSE-APACHE) files in the root directory of this source tree.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
2-
name = "buffer-unordered-weighted"
2+
name = "future-queue"
33
version = "0.1.2"
4-
description = "Stream::buffer_unordered where each future can have a different weight."
4+
description = "Adapters to manage a queue of futures, where each future can have a different weight."
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
readme = "README.md"
8-
repository = "https://github.com/nextest-rs/buffer-unordered-weighted"
8+
repository = "https://github.com/nextest-rs/future-queue"
99
resolver = "2"
1010
rust-version = "1.56"
1111
categories = ["asynchronous"]

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) The buffer-unordered-weighted Contributors
1+
Copyright (c) The future-queue Contributors
22

33
Permission is hereby granted, free of charge, to any
44
person obtaining a copy of this software and associated

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# buffer-unordered-weighted
1+
# future-queue
22

3-
[![buffer-unordered-weighted on crates.io](https://img.shields.io/crates/v/buffer-unordered-weighted)](https://crates.io/crates/buffer-unordered-weighted)
4-
[![Documentation (latest release)](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://docs.rs/buffer-unordered-weighted/)
5-
[![Documentation (main)](https://img.shields.io/badge/docs-main-purple)](https://nextest-rs.github.io/buffer-unordered-weighted/rustdoc/buffer_unordered_weighted)
3+
[![future-queue on crates.io](https://img.shields.io/crates/v/future-queue)](https://crates.io/crates/future-queue)
4+
[![Documentation (latest release)](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://docs.rs/future-queue/)
5+
[![Documentation (main)](https://img.shields.io/badge/docs-main-purple)](https://nextest-rs.github.io/future-queue/rustdoc/future_queue)
66
[![Changelog](https://img.shields.io/badge/changelog-latest-blue)](CHANGELOG.md)
77
[![License](https://img.shields.io/badge/license-Apache-green.svg)](LICENSE-APACHE)
88
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE-MIT)
99

10-
`buffer_unordered_weighted` is a variant of
10+
`future_queue` is a variant of
1111
[`buffer_unordered`](https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.buffer_unordered),
1212
where each future can be assigned a different weight.
1313

@@ -42,7 +42,7 @@ those tests should be run simultaneously.
4242

4343
## About this crate
4444

45-
This crate provides an adaptor on streams called `buffer_unordered_weighted`, which can run
45+
This crate provides an adaptor on streams called `future_queue`, which can run
4646
several futures simultaneously, limiting the concurrency to a maximum *weight*.
4747

4848
Rather than taking a stream of futures, this adaptor takes a stream of `(usize, future)` pairs,
@@ -64,27 +64,27 @@ the future.
6464

6565
The weight of a future can be zero, in which case it doesn't count towards the maximum weight.
6666

67-
If all weights are 1, then `buffer_unordered_weighted` is exactly the same as `buffer_unordered`.
67+
If all weights are 1, then `future_queue` is exactly the same as `buffer_unordered`.
6868

6969
## Examples
7070

7171
```rust
7272
use futures::{channel::oneshot, stream, StreamExt as _};
73-
use buffer_unordered_weighted::{StreamExt as _};
73+
use future_queue::{StreamExt as _};
7474

7575
let (send_one, recv_one) = oneshot::channel();
7676
let (send_two, recv_two) = oneshot::channel();
7777

7878
let stream_of_futures = stream::iter(vec![(1, recv_one), (2, recv_two)]);
79-
let mut buffered = stream_of_futures.buffer_unordered_weighted(10);
79+
let mut queue = stream_of_futures.future_queue(10);
8080

8181
send_two.send("hello")?;
82-
assert_eq!(buffered.next().await, Some(Ok("hello")));
82+
assert_eq!(queue.next().await, Some(Ok("hello")));
8383

8484
send_one.send("world")?;
85-
assert_eq!(buffered.next().await, Some(Ok("world")));
85+
assert_eq!(queue.next().await, Some(Ok("world")));
8686

87-
assert_eq!(buffered.next().await, None);
87+
assert_eq!(queue.next().await, None);
8888
```
8989

9090
## Minimum supported Rust version (MSRV)
@@ -95,6 +95,10 @@ The MSRV will likely not change in the medium term, but while this crate is a pr
9595
(0.x.x) it may have its MSRV bumped in a patch release. Once this crate has reached 1.x, any
9696
MSRV bump will be accompanied with a new minor version.
9797

98+
## Notes
99+
100+
This crate used to be called `buffer-unordered-weighted`. It was renamed to `future-queue` to be
101+
more descriptive about what the crate does rather than how it's implemented.
98102

99103
## Contributing
100104

README.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# {{crate}}
22

3-
[![buffer-unordered-weighted on crates.io](https://img.shields.io/crates/v/buffer-unordered-weighted)](https://crates.io/crates/buffer-unordered-weighted)
4-
[![Documentation (latest release)](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://docs.rs/buffer-unordered-weighted/)
5-
[![Documentation (main)](https://img.shields.io/badge/docs-main-purple)](https://nextest-rs.github.io/buffer-unordered-weighted/rustdoc/buffer_unordered_weighted)
3+
[![future-queue on crates.io](https://img.shields.io/crates/v/future-queue)](https://crates.io/crates/future-queue)
4+
[![Documentation (latest release)](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://docs.rs/future-queue/)
5+
[![Documentation (main)](https://img.shields.io/badge/docs-main-purple)](https://nextest-rs.github.io/future-queue/rustdoc/future_queue)
66
[![Changelog](https://img.shields.io/badge/changelog-latest-blue)](CHANGELOG.md)
77
[![License](https://img.shields.io/badge/license-Apache-green.svg)](LICENSE-APACHE)
88
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE-MIT)

src/future_queue.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) The buffer-unordered-weighted Contributors
1+
// Copyright (c) The future-queue Contributors
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

44
use futures_util::{
@@ -14,9 +14,9 @@ use std::{
1414
};
1515

1616
pin_project! {
17-
/// Stream for the [`buffer_unordered_weighted`](StreamExt::buffer_unordered_weighted) method.
17+
/// Stream for the [`future_queue`](StreamExt::future_queue) method.
1818
#[must_use = "streams do nothing unless polled"]
19-
pub struct BufferUnorderedWeighted<St>
19+
pub struct FutureQueue<St>
2020
where
2121
St: Stream,
2222
St::Item: WeightedFuture,
@@ -29,13 +29,13 @@ pin_project! {
2929
}
3030
}
3131

32-
impl<St> fmt::Debug for BufferUnorderedWeighted<St>
32+
impl<St> fmt::Debug for FutureQueue<St>
3333
where
3434
St: Stream + fmt::Debug,
3535
St::Item: WeightedFuture,
3636
{
3737
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38-
f.debug_struct("BufferUnorderedWeighted")
38+
f.debug_struct("FutureQueue")
3939
.field("stream", &self.stream)
4040
.field("in_progress_queue", &self.in_progress_queue)
4141
.field("max_weight", &self.max_weight)
@@ -44,7 +44,7 @@ where
4444
}
4545
}
4646

47-
impl<St> BufferUnorderedWeighted<St>
47+
impl<St> FutureQueue<St>
4848
where
4949
St: Stream,
5050
St::Item: WeightedFuture,
@@ -101,7 +101,7 @@ where
101101
}
102102
}
103103

104-
impl<St> Stream for BufferUnorderedWeighted<St>
104+
impl<St> Stream for FutureQueue<St>
105105
where
106106
St: Stream,
107107
St::Item: WeightedFuture,
@@ -120,9 +120,8 @@ where
120120
*this.current_weight =
121121
this.current_weight.checked_add(weight).unwrap_or_else(|| {
122122
panic!(
123-
"buffer_unordered_weighted: added weight {} to current {}, overflowed",
124-
weight,
125-
this.current_weight,
123+
"future_queue: added weight {} to current {}, overflowed",
124+
weight, this.current_weight,
126125
)
127126
});
128127
this.in_progress_queue
@@ -136,13 +135,13 @@ where
136135
match this.in_progress_queue.poll_next_unpin(cx) {
137136
Poll::Pending => return Poll::Pending,
138137
Poll::Ready(Some((weight, output))) => {
139-
*this.current_weight = this.current_weight.checked_sub(weight).unwrap_or_else(|| {
140-
panic!(
141-
"buffer_unordered_weighted: subtracted weight {} from current {}, overflowed",
142-
weight,
143-
this.current_weight,
144-
)
145-
});
138+
*this.current_weight =
139+
this.current_weight.checked_sub(weight).unwrap_or_else(|| {
140+
panic!(
141+
"future_queue: subtracted weight {} from current {}, overflowed",
142+
weight, this.current_weight,
143+
)
144+
});
146145
return Poll::Ready(Some(output));
147146
}
148147
Poll::Ready(None) => {}

src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Copyright (c) The buffer-unordered-weighted Contributors
1+
// Copyright (c) The future-queue Contributors
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
//! `buffer_unordered_weighted` is a variant of
4+
//! `future_queue` is a variant of
55
//! [`buffer_unordered`](https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.buffer_unordered),
66
//! where each future can be assigned a different weight.
77
//!
@@ -36,7 +36,7 @@
3636
//!
3737
//! # About this crate
3838
//!
39-
//! This crate provides an adaptor on streams called `buffer_unordered_weighted`, which can run
39+
//! This crate provides an adaptor on streams called `future_queue`, which can run
4040
//! several futures simultaneously, limiting the concurrency to a maximum *weight*.
4141
//!
4242
//! Rather than taking a stream of futures, this adaptor takes a stream of `(usize, future)` pairs,
@@ -58,28 +58,28 @@
5858
//!
5959
//! The weight of a future can be zero, in which case it doesn't count towards the maximum weight.
6060
//!
61-
//! If all weights are 1, then `buffer_unordered_weighted` is exactly the same as `buffer_unordered`.
61+
//! If all weights are 1, then `future_queue` is exactly the same as `buffer_unordered`.
6262
//!
6363
//! # Examples
6464
//!
6565
//! ```
6666
//! # futures::executor::block_on(async {
6767
//! use futures::{channel::oneshot, stream, StreamExt as _};
68-
//! use buffer_unordered_weighted::{StreamExt as _};
68+
//! use future_queue::{StreamExt as _};
6969
//!
7070
//! let (send_one, recv_one) = oneshot::channel();
7171
//! let (send_two, recv_two) = oneshot::channel();
7272
//!
7373
//! let stream_of_futures = stream::iter(vec![(1, recv_one), (2, recv_two)]);
74-
//! let mut buffered = stream_of_futures.buffer_unordered_weighted(10);
74+
//! let mut queue = stream_of_futures.future_queue(10);
7575
//!
7676
//! send_two.send("hello")?;
77-
//! assert_eq!(buffered.next().await, Some(Ok("hello")));
77+
//! assert_eq!(queue.next().await, Some(Ok("hello")));
7878
//!
7979
//! send_one.send("world")?;
80-
//! assert_eq!(buffered.next().await, Some(Ok("world")));
80+
//! assert_eq!(queue.next().await, Some(Ok("world")));
8181
//!
82-
//! assert_eq!(buffered.next().await, None);
82+
//! assert_eq!(queue.next().await, None);
8383
//! # Ok::<(), &'static str>(()) }).unwrap();
8484
//! ```
8585
//!
@@ -90,6 +90,11 @@
9090
//! The MSRV will likely not change in the medium term, but while this crate is a pre-release
9191
//! (0.x.x) it may have its MSRV bumped in a patch release. Once this crate has reached 1.x, any
9292
//! MSRV bump will be accompanied with a new minor version.
93+
//!
94+
//! # Notes
95+
//!
96+
//! This crate used to be called `buffer-unordered-weighted`. It was renamed to `future-queue` to be
97+
//! more descriptive about what the crate does rather than how it's implemented.
9398
9499
mod future_queue;
95100

@@ -98,7 +103,7 @@ use futures_util::{Future, Stream};
98103
impl<T: ?Sized> StreamExt for T where T: Stream {}
99104

100105
/// An extension trait for `Stream`s that provides
101-
/// [`buffer_unordered_weighted`](StreamExt::buffer_unordered_weighted).
106+
/// [`future_queue`](StreamExt::future_queue).
102107
pub trait StreamExt: Stream {
103108
/// An adaptor for creating a buffered list of pending futures (unordered), where
104109
/// each future has a different weight.
@@ -121,17 +126,12 @@ pub trait StreamExt: Stream {
121126
/// # Examples
122127
///
123128
/// See [the crate documentation](crate#examples) for an example.
124-
fn buffer_unordered_weighted<Fut>(
125-
self,
126-
max_weight: usize,
127-
) -> future_queue::BufferUnorderedWeighted<Self>
129+
fn future_queue<Fut>(self, max_weight: usize) -> future_queue::FutureQueue<Self>
128130
where
129131
Self: Sized + Stream<Item = (usize, Fut)>,
130132
Fut: Future,
131133
{
132-
assert_stream::<Fut::Output, _>(future_queue::BufferUnorderedWeighted::new(
133-
self, max_weight,
134-
))
134+
assert_stream::<Fut::Output, _>(future_queue::FutureQueue::new(self, max_weight))
135135
}
136136
}
137137

tests/test_properties.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Copyright (c) The buffer-unordered-weighted Contributors
1+
// Copyright (c) The future-queue Contributors
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
use buffer_unordered_weighted::StreamExt as _;
4+
use future_queue::StreamExt as _;
55
use futures::{stream, StreamExt as _};
66
use proptest::prelude::*;
77
use proptest_derive::Arbitrary;
@@ -30,8 +30,8 @@ fn duration_strategy() -> BoxedStrategy<Duration> {
3030

3131
proptest! {
3232
#[test]
33-
fn proptest_buffer_unordered(state: TestState) {
34-
proptest_buffer_unordered_impl(state)
33+
fn proptest_future_queue(state: TestState) {
34+
proptest_future_queue_impl(state)
3535
}
3636
}
3737

@@ -41,7 +41,7 @@ enum FutureEvent {
4141
Finished(usize, TestFutureDesc),
4242
}
4343

44-
fn proptest_buffer_unordered_impl(state: TestState) {
44+
fn proptest_future_queue_impl(state: TestState) {
4545
let runtime = tokio::runtime::Builder::new_current_thread()
4646
.enable_time()
4747
.start_paused(true)
@@ -75,7 +75,7 @@ fn proptest_buffer_unordered_impl(state: TestState) {
7575

7676
runtime.block_on(async move {
7777
// Record values that have been completed in this map.
78-
let mut stream = stream.buffer_unordered_weighted(state.max_weight);
78+
let mut stream = stream.future_queue(state.max_weight);
7979
loop {
8080
tokio::select! {
8181
// biased ensures that the receiver is drained before the stream is polled. Without

0 commit comments

Comments
 (0)