Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1 @@
{"files":{"CHANGELOG.md":"db6256a24e1125aa9b2113ab0862cfce73b6e8e8ad4db2a8b4975f1456e9df27","Cargo.toml":"3fcc48c441e4598ef367ad143b94ef96e40abcb9c2587f59dbafc61ffc434356","LICENSE-APACHE":"e4705ddab847449a2cdcb3c88b005ea10330aa249d9148ca2eef9c84c5d29895","LICENSE-MIT":"24e5860bf589d8501643e6ea51ffb3df66db2867492b09033d486183efbfa970","README.md":"d9b2126fb5e3f158b62d91af995e36a79d875801530ef6bca0cae06d03fe50ee","benches/broadcast_bench.rs":"eadc2b2879d6bed90e52d55f624d0caa8224f66557b5361edee812976b8c9822","src/lib.rs":"aa5c57e7b5630ddb6662dc4c7efe35c29557f6d13d5b3844c424f14152cdcd23","tests/test.rs":"b7569761c015ca281f5c1d069a7f44342281f7681cca35dc81b8edd686353861"},"package":"435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"}

80
vendor/async-broadcast/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,80 @@
# Version 0.7.2
- Add `Sender::broadcast_blocking` and `Receiver::recv_blocking`. #41
- Use `Mutex` instead of `RwLock` for securing the inner data. #42
- Many non-user-facing internal improvements and fixes.
# Version 0.7.1
- Add a `poll_recv()` method to the `Receiver` type. This allows for `Receiver`
to be used in `poll`-based contexts. (#56)
# Version 0.7.0
- **Breaking:** `Recv` and `Send` are now `!Unpin` to allow for future optimizations.
- Port to event-listener v5.0.
# Version 0.6.0
- Bump to event-listener v3.0.0.
- Add smol-rs logo to docs.
# Version 0.5.1
- Drop `parking_lot` dependency, in favor of sync primitives in std.
# Version 0.5.0
- API to disable waiting for active receivers (#35).
# Version 0.4.1
- Drop unneeded easy-parallel dep.
- Bumb dependencies to the current versions.
- Update `parking_lot` to 0.12.1.
- fix incorrect documentation for `TrySendError::is_disconnected`.
# Version 0.4.0
- Add `RecvError::Overflowed` for detecting missing messages.
- Avoid overflows on 32- and 16-bit systems (#22).
- Add overflow message count.
- `Clone` impl of `Receiver` now properly duplicates it.
- Add `Receiver::new_receiver`.
- Add `Receiver::new_sender` and `Sender::new_receiver`, allowing generating senders from receivers
and vice versa, respectively.
- Switch to `parking_lot::RwLock` instead of `std::sync::Mutex`.
# Version 0.3.4
- Avoid the last clone in `try_recv` (#18).
- Add some basic benchmarks.
# Version 0.3.3
- Close channel if the last receiver to drop is inactive.
# Version 0.3.2
- Fix a underflow panic (#14).
- Document difference with other broadcast APIs.
# Version 0.3.1
- Channel API in InactiveReceiver (#11).
- {Sender,Receiver}::inactive_receiver_count method.
# Version 0.3.0
- overflow mode.
- ability to modify channel capacity.
- Inactive receivers (#2).
- Document difference to `async-channel` crate (#6).
# Version 0.2.0
- First real release.
# Version 0.1.0
- Dummy release to get the name registered on crates.io.

76
vendor/async-broadcast/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,76 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.60"
name = "async-broadcast"
version = "0.7.2"
authors = [
"Stjepan Glavina <stjepang@gmail.com>",
"Yoshua Wuyts <yoshuawuyts@gmail.com>",
"Zeeshan Ali Khan <zeeshanak@gnome.org>",
]
build = false
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Async broadcast channels"
documentation = "https://docs.rs/async-broadcast"
readme = "README.md"
keywords = []
categories = []
license = "MIT OR Apache-2.0"
repository = "https://github.com/smol-rs/async-broadcast"
[lib]
name = "async_broadcast"
path = "src/lib.rs"
[[test]]
name = "test"
path = "tests/test.rs"
[[bench]]
name = "broadcast_bench"
path = "benches/broadcast_bench.rs"
harness = false
[dependencies.event-listener]
version = "5.0.0"
[dependencies.event-listener-strategy]
version = "0.5.0"
[dependencies.futures-core]
version = "0.3.21"
[dependencies.pin-project-lite]
version = "0.2.13"
[dev-dependencies.criterion]
version = "0.3.5"
[dev-dependencies.doc-comment]
version = "0.3.3"
[dev-dependencies.easy-parallel]
version = "3.2.0"
[dev-dependencies.futures-lite]
version = "1.11.3"
[dev-dependencies.futures-util]
version = "0.3.21"
[features]

190
vendor/async-broadcast/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,190 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2020 Yoshua Wuyts
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

21
vendor/async-broadcast/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2020 Yoshua Wuyts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

131
vendor/async-broadcast/README.md vendored Normal file
View File

@@ -0,0 +1,131 @@
# async-broadcast
[![Build](https://github.com/smol-rs/async-broadcast/workflows/Build%20and%20test/badge.svg)](
https://github.com/smol-rs/async-broadcast/actions)
[![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](
https://github.com/smol-rs/async-broadcast)
[![Cargo](https://img.shields.io/crates/v/async-broadcast.svg)](
https://crates.io/crates/async-broadcast)
[![Documentation](https://docs.rs/async-broadcast/badge.svg)](
https://docs.rs/async-broadcast)
An async multi-producer multi-consumer broadcast channel, where each consumer gets a clone of every
message sent on the channel. For obvious reasons, the channel can only be used to broadcast types
that implement `Clone`.
A channel has the `Sender` and `Receiver` side. Both sides are cloneable and can be shared
among multiple threads.
When all `Sender`s or all `Receiver`s are dropped, the channel becomes closed. When a channel is
closed, no more messages can be sent, but remaining messages can still be received.
The channel can also be closed manually by calling `Sender::close()` or
`Receiver::close()`.
## Examples
```rust
use async_broadcast::{broadcast, TryRecvError};
use futures_lite::{future::block_on, stream::StreamExt};
block_on(async move {
let (s1, mut r1) = broadcast(2);
let s2 = s1.clone();
let mut r2 = r1.clone();
// Send 2 messages from two different senders.
s1.broadcast(7).await.unwrap();
s2.broadcast(8).await.unwrap();
// Channel is now at capacity so sending more messages will result in an error.
assert!(s2.try_broadcast(9).unwrap_err().is_full());
assert!(s1.try_broadcast(10).unwrap_err().is_full());
// We can use `recv` method of the `Stream` implementation to receive messages.
assert_eq!(r1.next().await.unwrap(), 7);
assert_eq!(r1.recv().await.unwrap(), 8);
assert_eq!(r2.next().await.unwrap(), 7);
assert_eq!(r2.recv().await.unwrap(), 8);
// All receiver got all messages so channel is now empty.
assert_eq!(r1.try_recv(), Err(TryRecvError::Empty));
assert_eq!(r2.try_recv(), Err(TryRecvError::Empty));
// Drop both senders, which closes the channel.
drop(s1);
drop(s2);
assert_eq!(r1.try_recv(), Err(TryRecvError::Closed));
assert_eq!(r2.try_recv(), Err(TryRecvError::Closed));
})
```
## Difference with `async-channel`
This crate is similar to [`async-channel`] in that they both provide an MPMC channel but the main
difference being that in `async-channel`, each message sent on the channel is only received by one
of the receivers. `async-broadcast` on the other hand, delivers each message to every receiver
(IOW broadcast) by cloning it for each receiver.
[`async-channel`]: https://crates.io/crates/async-channel
## Difference with other broadcast crates
* [`broadcaster`]: The main difference would be that `broadcaster` doesn't have a sender and
receiver split and both sides use clones of the same BroadcastChannel instance. The messages are
sent are sent to all channel clones. While this can work for many cases, the lack of sender and
receiver split, means that often times, you'll find yourself having to drain the channel on the
sending side yourself.
* [`postage`]: this crate provides a [broadcast API][pba] similar to `async_broadcast`. However, it:
- (at the time of this writing) duplicates [futures] API, which isn't ideal.
- Does not support overflow mode nor has the concept of inactive receivers, so a slow or inactive
receiver blocking the whole channel is not a solvable problem.
- Provides all kinds of channels, which is generally good but if you just need a broadcast
channel, `async_broadcast` is probably a better choice.
* [`tokio::sync`]: Tokio's `sync` module provides a [broadcast channel][tbc] API. The differences
here are:
- While this implementation does provide [overflow mode][tom], it is the default behavior and not
opt-in.
- There is no equivalent of inactive receivers.
- While it's possible to build tokio with only the `sync` module, it comes with other APIs that
you may not need.
[`broadcaster`]: https://crates.io/crates/broadcaster
[`postage`]: https://crates.io/crates/postage
[pba]: https://docs.rs/postage/0.4.1/postage/broadcast/fn.channel.html
[futures]: https://crates.io/crates/futures
[`tokio::sync`]: https://docs.rs/tokio/1.6.0/tokio/sync
[tbc]: https://docs.rs/tokio/1.6.0/tokio/sync/broadcast/index.html
[tom]: https://docs.rs/tokio/1.6.0/tokio/sync/broadcast/index.html#lagging
## Safety
This crate uses ``#![deny(unsafe_code)]`` to ensure everything is implemented in
100% Safe Rust.
## Contributing
Want to join us? Check out our ["Contributing" guide][contributing] and take a
look at some of these issues:
- [Issues labeled "good first issue"][good-first-issue]
- [Issues labeled "help wanted"][help-wanted]
[contributing]: https://github.com/smol-rs/async-broadcast/blob/master/.github/CONTRIBUTING.md
[good-first-issue]: https://github.com/smol-rs/async-broadcast/labels/good%20first%20issue
[help-wanted]: https://github.com/smol-rs/async-broadcast/labels/help%20wanted
## License
<sup>
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
</sup>
<br/>
<sub>
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.
</sub>

View File

@@ -0,0 +1,71 @@
use async_broadcast::broadcast;
use criterion::{criterion_group, criterion_main, Criterion};
use futures_lite::future::block_on;
pub fn broadcast_and_recv(c: &mut Criterion) {
let (s, mut r1) = broadcast(1);
let mut n = 0;
c.bench_function("1 -> 1", |b| {
b.iter(|| {
block_on(async {
s.broadcast(n).await.unwrap();
assert_eq!(r1.recv().await.unwrap(), n);
n += 1;
})
})
});
let mut r2 = r1.clone();
c.bench_function("1 -> 2", |b| {
b.iter(|| {
block_on(async {
s.broadcast(n).await.unwrap();
assert_eq!(r1.recv().await.unwrap(), n);
assert_eq!(r2.recv().await.unwrap(), n);
n += 1;
})
})
});
let mut r3 = r1.clone();
let mut r4 = r1.clone();
c.bench_function("1 -> 4", |b| {
b.iter(|| {
block_on(async {
s.broadcast(n).await.unwrap();
assert_eq!(r1.recv().await.unwrap(), n);
assert_eq!(r2.recv().await.unwrap(), n);
assert_eq!(r3.recv().await.unwrap(), n);
assert_eq!(r4.recv().await.unwrap(), n);
n += 1;
})
})
});
let mut r5 = r1.clone();
let mut r6 = r1.clone();
let mut r7 = r1.clone();
let mut r8 = r1.clone();
c.bench_function("1 -> 8", |b| {
b.iter(|| {
block_on(async {
s.broadcast(n).await.unwrap();
assert_eq!(r1.recv().await.unwrap(), n);
assert_eq!(r2.recv().await.unwrap(), n);
assert_eq!(r3.recv().await.unwrap(), n);
assert_eq!(r4.recv().await.unwrap(), n);
assert_eq!(r5.recv().await.unwrap(), n);
assert_eq!(r6.recv().await.unwrap(), n);
assert_eq!(r7.recv().await.unwrap(), n);
assert_eq!(r8.recv().await.unwrap(), n);
n += 1;
})
})
});
}
criterion_group!(benches, broadcast_and_recv);
criterion_main!(benches);

2098
vendor/async-broadcast/src/lib.rs vendored Normal file

File diff suppressed because it is too large Load Diff

342
vendor/async-broadcast/tests/test.rs vendored Normal file
View File

@@ -0,0 +1,342 @@
use std::{sync::mpsc, thread::sleep, time::Duration};
use async_broadcast::*;
use futures_util::{future::join, stream::StreamExt};
use easy_parallel::Parallel;
use futures_lite::future::block_on;
fn ms(ms: u64) -> Duration {
Duration::from_millis(ms)
}
#[test]
fn basic_sync() {
let (s, mut r1) = broadcast(10);
let mut r2 = r1.clone();
s.try_broadcast(7).unwrap();
assert_eq!(r1.try_recv().unwrap(), 7);
assert_eq!(r2.try_recv().unwrap(), 7);
let mut r3 = r1.clone();
s.try_broadcast(8).unwrap();
assert_eq!(r1.try_recv().unwrap(), 8);
assert_eq!(r2.try_recv().unwrap(), 8);
assert_eq!(r3.try_recv().unwrap(), 8);
}
#[test]
fn basic_async() {
block_on(async {
let (s, mut r1) = broadcast(10);
let mut r2 = r1.clone();
s.broadcast(7).await.unwrap();
assert_eq!(r1.recv().await.unwrap(), 7);
assert_eq!(r2.recv().await.unwrap(), 7);
// Now let's try the Stream impl.
let mut r3 = r1.clone();
s.broadcast(8).await.unwrap();
assert_eq!(r1.next().await.unwrap(), 8);
assert_eq!(r2.next().await.unwrap(), 8);
assert_eq!(r3.next().await.unwrap(), 8);
});
}
#[cfg(not(target_family = "wasm"))]
#[test]
fn basic_blocking() {
let (s, mut r) = broadcast(1);
s.broadcast_blocking(7).unwrap();
assert_eq!(r.try_recv(), Ok(7));
s.broadcast_blocking(8).unwrap();
assert_eq!(block_on(r.recv()), Ok(8));
block_on(s.broadcast(9)).unwrap();
assert_eq!(r.recv_blocking(), Ok(9));
assert_eq!(r.try_recv(), Err(TryRecvError::Empty));
}
#[test]
fn parallel() {
let (s1, mut r1) = broadcast(2);
let s2 = s1.clone();
let mut r2 = r1.clone();
let (sender_sync_send, sender_sync_recv) = mpsc::channel();
let (receiver_sync_send, receiver_sync_recv) = mpsc::channel();
Parallel::new()
.add(move || {
sender_sync_recv.recv().unwrap();
s1.try_broadcast(7).unwrap();
s2.try_broadcast(8).unwrap();
assert!(s2.try_broadcast(9).unwrap_err().is_full());
assert!(s1.try_broadcast(10).unwrap_err().is_full());
receiver_sync_send.send(()).unwrap();
drop(s1);
drop(s2);
receiver_sync_send.send(()).unwrap();
})
.add(move || {
assert_eq!(r1.try_recv(), Err(TryRecvError::Empty));
assert_eq!(r2.try_recv(), Err(TryRecvError::Empty));
sender_sync_send.send(()).unwrap();
receiver_sync_recv.recv().unwrap();
assert_eq!(r1.try_recv().unwrap(), 7);
assert_eq!(r1.try_recv().unwrap(), 8);
assert_eq!(r2.try_recv().unwrap(), 7);
assert_eq!(r2.try_recv().unwrap(), 8);
receiver_sync_recv.recv().unwrap();
assert_eq!(r1.try_recv(), Err(TryRecvError::Closed));
assert_eq!(r2.try_recv(), Err(TryRecvError::Closed));
})
.run();
}
#[test]
fn parallel_async() {
let (s1, mut r1) = broadcast(2);
let s2 = s1.clone();
let mut r2 = r1.clone();
let (sender_sync_send, sender_sync_recv) = mpsc::channel();
let (receiver_sync_send, receiver_sync_recv) = mpsc::channel();
Parallel::new()
.add(move || {
block_on(async move {
sender_sync_recv.recv().unwrap();
sleep(ms(5));
s1.broadcast(7).await.unwrap();
s2.broadcast(8).await.unwrap();
assert!(s2.try_broadcast(9).unwrap_err().is_full());
assert!(s1.try_broadcast(10).unwrap_err().is_full());
receiver_sync_send.send(()).unwrap();
s1.broadcast(9).await.unwrap();
s2.broadcast(10).await.unwrap();
drop(s1);
drop(s2);
receiver_sync_send.send(()).unwrap();
})
})
.add(move || {
block_on(async move {
assert_eq!(r1.try_recv(), Err(TryRecvError::Empty));
assert_eq!(r2.try_recv(), Err(TryRecvError::Empty));
sender_sync_send.send(()).unwrap();
receiver_sync_recv.recv().unwrap();
assert_eq!(r1.next().await.unwrap(), 7);
assert_eq!(r2.next().await.unwrap(), 7);
assert_eq!(r1.recv().await.unwrap(), 8);
assert_eq!(r2.recv().await.unwrap(), 8);
receiver_sync_recv.recv().unwrap();
sleep(ms(5));
assert_eq!(r1.next().await.unwrap(), 9);
assert_eq!(r2.next().await.unwrap(), 9);
assert_eq!(r1.recv().await.unwrap(), 10);
assert_eq!(r2.recv().await.unwrap(), 10);
assert_eq!(r1.recv().await, Err(RecvError::Closed));
assert_eq!(r2.recv().await, Err(RecvError::Closed));
})
})
.run();
}
#[test]
fn channel_shrink() {
let (s1, mut r1) = broadcast(4);
let mut r2 = r1.clone();
let mut r3 = r1.clone();
let mut r4 = r1.clone();
s1.try_broadcast(1).unwrap();
s1.try_broadcast(2).unwrap();
s1.try_broadcast(3).unwrap();
s1.try_broadcast(4).unwrap();
assert_eq!(r2.try_recv().unwrap(), 1);
assert_eq!(r2.try_recv().unwrap(), 2);
assert_eq!(r3.try_recv().unwrap(), 1);
assert_eq!(r3.try_recv().unwrap(), 2);
assert_eq!(r3.try_recv().unwrap(), 3);
assert_eq!(r4.try_recv().unwrap(), 1);
assert_eq!(r4.try_recv().unwrap(), 2);
assert_eq!(r4.try_recv().unwrap(), 3);
assert_eq!(r4.try_recv().unwrap(), 4);
r1.set_capacity(2);
assert_eq!(r1.try_recv(), Err(TryRecvError::Overflowed(2)));
assert_eq!(r1.try_recv().unwrap(), 3);
assert_eq!(r1.try_recv().unwrap(), 4);
assert_eq!(r1.try_recv(), Err(TryRecvError::Empty));
assert_eq!(r2.try_recv().unwrap(), 3);
assert_eq!(r2.try_recv().unwrap(), 4);
assert_eq!(r2.try_recv(), Err(TryRecvError::Empty));
assert_eq!(r3.try_recv().unwrap(), 4);
assert_eq!(r3.try_recv(), Err(TryRecvError::Empty));
assert_eq!(r4.try_recv(), Err(TryRecvError::Empty));
}
#[test]
fn overflow() {
let (s1, mut r1) = broadcast(2);
r1.set_overflow(true);
// We'll keep r1 as the lagging receiver.
let mut r2 = r1.clone();
let mut r3 = r1.clone();
let (sender_sync_send, sender_sync_recv) = mpsc::channel();
Parallel::new()
.add(move || {
block_on(async move {
s1.broadcast(7).await.unwrap();
s1.broadcast(8).await.unwrap();
sender_sync_recv.recv().unwrap();
sleep(ms(5));
s1.broadcast(9).await.unwrap();
sender_sync_recv.recv().unwrap();
})
})
.add(move || {
block_on(async move {
assert_eq!(r2.next().await.unwrap(), 7);
assert_eq!(r2.recv().await.unwrap(), 8);
sender_sync_send.send(()).unwrap();
assert_eq!(r2.next().await.unwrap(), 9);
sender_sync_send.send(()).unwrap();
})
})
.add(move || {
block_on(async move {
assert_eq!(r3.next().await.unwrap(), 7);
assert_eq!(r3.recv().await.unwrap(), 8);
assert_eq!(r3.next().await.unwrap(), 9);
})
})
.run();
assert_eq!(r1.try_recv(), Err(TryRecvError::Overflowed(1)));
assert_eq!(r1.try_recv().unwrap(), 8);
assert_eq!(r1.try_recv().unwrap(), 9);
}
#[test]
fn open_channel() {
let (s1, r) = broadcast(2);
let inactive = r.deactivate();
let s2 = s1.clone();
let (receiver_sync_send, receiver_sync_recv) = mpsc::channel();
let (sender_sync_send, sender_sync_recv) = mpsc::channel();
Parallel::new()
.add(move || {
block_on(async move {
receiver_sync_send.send(()).unwrap();
let (result1, result2) = join(s1.broadcast(7), s2.broadcast(8)).await;
result1.unwrap();
result2.unwrap();
sender_sync_recv.recv().unwrap();
assert_eq!(s1.try_broadcast(9), Err(TrySendError::Inactive(9)));
assert_eq!(s2.try_broadcast(10), Err(TrySendError::Inactive(10)));
receiver_sync_send.send(()).unwrap();
sleep(ms(5));
s1.broadcast(9).await.unwrap();
s2.broadcast(10).await.unwrap();
})
})
.add(move || {
block_on(async move {
receiver_sync_recv.recv().unwrap();
sleep(ms(5));
let mut r = inactive.activate_cloned();
assert_eq!(r.next().await.unwrap(), 7);
assert_eq!(r.recv().await.unwrap(), 8);
drop(r);
sender_sync_send.send(()).unwrap();
receiver_sync_recv.recv().unwrap();
let mut r = inactive.activate();
assert_eq!(r.recv().await.unwrap(), 9);
assert_eq!(r.recv().await.unwrap(), 10);
})
})
.run();
}
#[test]
fn inactive_drop() {
let (s, active_receiver) = broadcast::<()>(1);
let inactive = active_receiver.deactivate();
let inactive2 = inactive.clone();
drop(inactive);
drop(inactive2);
assert!(s.is_closed())
}
#[test]
fn poll_recv() {
let (s, mut r) = broadcast::<i32>(2);
r.set_overflow(true);
// A quick custom stream impl to demonstrate/test `poll_recv`.
struct MyStream(Receiver<i32>);
impl futures_core::Stream for MyStream {
type Item = Result<i32, RecvError>;
fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
std::pin::Pin::new(&mut self.0).poll_recv(cx)
}
}
block_on(async move {
let mut stream = MyStream(r);
s.broadcast(1).await.unwrap();
s.broadcast(2).await.unwrap();
s.broadcast(3).await.unwrap();
s.broadcast(4).await.unwrap();
assert_eq!(stream.next().await.unwrap(), Err(RecvError::Overflowed(2)));
assert_eq!(stream.next().await.unwrap(), Ok(3));
assert_eq!(stream.next().await.unwrap(), Ok(4));
drop(s);
assert_eq!(stream.next().await, None);
})
}