2
我認爲.for_each()
會做的伎倆,但它只返回渠道的第一個(未來)項目,然後返回,如果通道是空的。在非Tokio /未來上下文中,無限期地讀取任務中的頻道的方式是.for_each()
?如何無限期讀取Rust Tokio任務中的無限制頻道?
let tx_origs_reader = rx_chan.for_each(move |tx_orig| {
//save receiver side tx to db
let mut tx_origs_once = tx_origs_inner.borrow_mut();
tx_origs_once.push(tx_orig.clone());
Ok(())
});
handle.spawn(tx_origs_reader.then(|err| {
println!("This returns after first item without an error {:?}", err);
Ok(())
}));
歡迎來到Stack Overflow!如果您提供[MCVE],您的問題將更有可能在合理的時間內回答。就像現在一樣,你要求*每個*潛在的回答者從頭開始構建一個完整的程序,**猜測你所顯示的每個變量的類型。 – Shepmaster