Skip to content

Commit c34ac2d

Browse files
Noah-Kennedyhawkw
authored andcommitted
fix(subscriber): fix build on tokio 1.21.0 (#374)
Due to a change in the unstable task builder APIs, this no longer compiles with the latest version of Tokio. Fortunately, it's a simple fix.
1 parent c903b33 commit c34ac2d

File tree

8 files changed

+102
-35
lines changed

8 files changed

+102
-35
lines changed

Cargo.lock

Lines changed: 56 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console-subscriber/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ serde_json = "1"
5454
crossbeam-channel = "0.5"
5555

5656
[dev-dependencies]
57-
tokio = { version = "^1.7", features = ["full", "rt-multi-thread"] }
57+
tokio = { version = "^1.21", features = ["full", "rt-multi-thread"] }
5858
futures = "0.3"
5959

6060
[package.metadata.docs.rs]

console-subscriber/examples/app.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2323
"blocks" => {
2424
tokio::task::Builder::new()
2525
.name("blocks")
26-
.spawn(double_sleepy(1, 10));
26+
.spawn(double_sleepy(1, 10))
27+
.unwrap();
2728
}
2829
"coma" => {
2930
tokio::task::Builder::new()
3031
.name("coma")
31-
.spawn(std::future::pending::<()>());
32+
.spawn(std::future::pending::<()>())
33+
.unwrap();
3234
}
3335
"burn" => {
34-
tokio::task::Builder::new().name("burn").spawn(burn(1, 10));
36+
tokio::task::Builder::new()
37+
.name("burn")
38+
.spawn(burn(1, 10))
39+
.unwrap();
3540
}
3641
"help" | "-h" => {
3742
eprintln!("{}", HELP);
@@ -47,10 +52,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
4752

4853
let task1 = tokio::task::Builder::new()
4954
.name("task1")
50-
.spawn(spawn_tasks(1, 10));
55+
.spawn(spawn_tasks(1, 10))
56+
.unwrap();
5157
let task2 = tokio::task::Builder::new()
5258
.name("task2")
53-
.spawn(spawn_tasks(10, 30));
59+
.spawn(spawn_tasks(10, 30))
60+
.unwrap();
5461

5562
let result = tokio::try_join! {
5663
task1,
@@ -66,7 +73,10 @@ async fn spawn_tasks(min: u64, max: u64) {
6673
loop {
6774
for i in min..max {
6875
tracing::trace!(i, "spawning wait task");
69-
tokio::task::Builder::new().name("wait").spawn(wait(i));
76+
tokio::task::Builder::new()
77+
.name("wait")
78+
.spawn(wait(i))
79+
.unwrap();
7080

7181
let sleep = Duration::from_secs(max) - Duration::from_secs(i);
7282
tracing::trace!(?sleep, "sleeping...");

console-subscriber/examples/barrier.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
1414
for i in 0..30 {
1515
let c = barrier.clone();
1616
let task_name = format!("task-{}", i);
17-
handles.push(task::Builder::default().name(&task_name).spawn(async move {
18-
tokio::time::sleep(Duration::from_secs(i)).await;
19-
c.wait().await
20-
}));
17+
handles.push(
18+
task::Builder::default()
19+
.name(&task_name)
20+
.spawn(async move {
21+
tokio::time::sleep(Duration::from_secs(i)).await;
22+
c.wait().await
23+
})
24+
.unwrap(),
25+
);
2126
}
2227

2328
// Will not resolve until all "after wait" messages have been printed
@@ -33,6 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
3338
// Exactly one barrier will resolve as the "leader"
3439
assert_eq!(num_leaders, 1);
3540
})
41+
.unwrap()
3642
.await?;
3743

3844
Ok(())

console-subscriber/examples/mutex.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2020
*lock += 1;
2121
tokio::time::sleep(Duration::from_secs(1)).await;
2222
}
23-
});
23+
})
24+
.unwrap();
2425
}
2526

2627
while *count.lock().await < 50 {}
2728
})
29+
.unwrap()
2830
.await?;
2931

3032
Ok(())

console-subscriber/examples/rwlock.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2020
*lock += 1;
2121
tokio::time::sleep(Duration::from_secs(1)).await;
2222
}
23-
});
23+
})
24+
.unwrap();
2425
}
2526

2627
loop {
@@ -31,6 +32,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
3132
}
3233
}
3334
})
35+
.unwrap()
3436
.await?;
3537

3638
Ok(())

console-subscriber/examples/semaphore.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2121
.spawn(async move {
2222
let _permit = acquire_sem.acquire_many(i).await.unwrap();
2323
tokio::time::sleep(Duration::from_secs(i as u64 * 2)).await;
24-
}),
24+
})
25+
.unwrap(),
26+
);
27+
tasks.push(
28+
tokio::task::Builder::default()
29+
.name(&add_task_name)
30+
.spawn(async move {
31+
tokio::time::sleep(Duration::from_secs(i as u64 * 5)).await;
32+
add_sem.add_permits(i as usize);
33+
})
34+
.unwrap(),
2535
);
26-
tasks.push(tokio::task::Builder::default().name(&add_task_name).spawn(
27-
async move {
28-
tokio::time::sleep(Duration::from_secs(i as u64 * 5)).await;
29-
add_sem.add_permits(i as usize);
30-
},
31-
));
3236
}
3337

3438
let all_tasks = futures::future::try_join_all(tasks);
3539
all_tasks.await.unwrap();
3640
})
41+
.unwrap()
3742
.await?;
3843

3944
Ok(())

console-subscriber/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ where
10631063
T: Send + 'static,
10641064
{
10651065
#[cfg(tokio_unstable)]
1066-
return tokio::task::Builder::new().name(_name).spawn(task);
1066+
return tokio::task::Builder::new().name(_name).spawn(task).unwrap();
10671067

10681068
#[cfg(not(tokio_unstable))]
10691069
tokio::spawn(task)

0 commit comments

Comments
 (0)