Function tdn::prelude::new_receive_channel
source ยท pub fn new_receive_channel(
) -> (Sender<ReceiveMessage>, Receiver<ReceiveMessage>)
Expand description
new a channel, send message to TDN Message. default capacity is 1024.
Examples found in repository?
examples/stop.rs (line 9)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
async fn main() {
let config = Config::load(PathBuf::from("./")).await;
let (_secret, ids, p2p_config, _rpc_config) = config.split();
let (send_send, send_recv) = new_send_channel();
let (recv_send, mut recv_recv) = new_receive_channel();
let peer_id = start_main(ids, p2p_config, recv_send, send_recv, None, None)
.await
.unwrap();
println!("Example: peer id: {:?}", peer_id);
println!("Network will stop after 5s...");
tokio::time::sleep(Duration::from_secs(5)).await;
let _ = send_send
.send(SendMessage::Network(NetworkType::NetworkStop))
.await;
while let Some(_) = recv_recv.recv().await {
//
}
println!("Network is stopped.");
}