mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
task: add JoinMap::keys (#6046)
Co-authored-by: Alice Ryhl <[email protected]>
This commit is contained in:
co-authored by
Alice Ryhl
parent
f9335b8186
commit
f1e41a4ad4
@@ -109,6 +109,30 @@ async fn alternating() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_keys() {
|
||||
use std::collections::HashSet;
|
||||
|
||||
let mut map = JoinMap::new();
|
||||
|
||||
assert_eq!(map.len(), 0);
|
||||
map.spawn(1, async {});
|
||||
assert_eq!(map.len(), 1);
|
||||
map.spawn(2, async {});
|
||||
assert_eq!(map.len(), 2);
|
||||
|
||||
let keys = map.keys().collect::<HashSet<&u32>>();
|
||||
assert!(keys.contains(&1));
|
||||
assert!(keys.contains(&2));
|
||||
|
||||
let _ = map.join_next().await.unwrap();
|
||||
let _ = map.join_next().await.unwrap();
|
||||
|
||||
assert_eq!(map.len(), 0);
|
||||
let keys = map.keys().collect::<HashSet<&u32>>();
|
||||
assert!(keys.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn abort_by_key() {
|
||||
let mut map = JoinMap::new();
|
||||
|
||||
Reference in New Issue
Block a user