【发布时间】:2019-10-26 13:45:24
【问题描述】:
我想终止从tokio::io::lines 流中读取。我将它与 oneshot 未来合并并终止了它,但 tokio::run 仍在工作。
use futures::{sync::oneshot, *}; // 0.1.27
use std::{io::BufReader, time::Duration};
use tokio::prelude::*; // 0.1.21
fn main() {
let (tx, rx) = oneshot::channel::<()>();
let lines = tokio::io::lines(BufReader::new(tokio::io::stdin()));
let lines = lines.for_each(|item| {
println!("> {:?}", item);
Ok(())
});
std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(5000));
println!("system shutting down");
let _ = tx.send(());
});
let lines = lines.select2(rx);
tokio::run(lines.map(|_| ()).map_err(|_| ()));
}
我怎样才能停止阅读这个?
【问题讨论】:
标签: rust rust-tokio