1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "channels")]
wrap_it::run().await?;
Ok(())
}
#[cfg(feature = "channels")]
mod wrap_it {
use super::*;
use holochain_trace::{channel::mpsc, span_context};
use tracing::*;
#[derive(Debug)]
struct Foo;
struct MyChannel {
rx: mpsc::Receiver<Foo>,
tx: mpsc::Sender<Foo>,
}
impl MyChannel {
fn new(tx: mpsc::Sender<Foo>, rx: mpsc::Receiver<Foo>) -> Self {
Self { rx, tx }
}
}
pub async fn run() -> Result<(), Box<dyn Error>> {
holochain_trace::test_run_open().ok();
let (tx1, rx2) = mpsc::channel(10);
let (tx2, rx1) = mpsc::channel(10);
let c1 = MyChannel::new(tx1.clone(), rx1);
let c2 = MyChannel::new(tx2, rx2);
let (tx4, rx4) = mpsc::channel(10);
let (_, dead) = mpsc::channel(1);
let c3 = MyChannel::new(tx1, rx4);
let c4 = MyChannel::new(tx4, dead);
let mut jh = Vec::new();
jh.push(tokio::task::spawn(async { a(c1).await.unwrap() }));
jh.push(tokio::task::spawn(async { b(c2, c4).await.unwrap() }));
jh.push(tokio::task::spawn(async { c(c3).await.unwrap() }));
for h in jh {
h.await?;
}
Ok(())
}
#[cfg_attr(feature = "instrument", tracing::instrument(skip(channel)))]
async fn a(mut channel: MyChannel) -> Result<(), Box<dyn Error>> {
for _ in 0..10 {
span_context!(Span::current());
channel.tx.send(Foo).await?;
if let Some(_) = channel.rx.recv().await {}
}
tokio::time::delay_for(std::time::Duration::from_millis(500)).await;
Ok(())
}
#[cfg_attr(feature = "instrument", tracing::instrument(skip(channel, to_c)))]
async fn b(mut channel: MyChannel, mut to_c: MyChannel) -> Result<(), Box<dyn Error>> {
for _ in 0..10 {
span_context!(Span::current());
if let Some(_) = channel.rx.recv().await {}
channel.tx.send(Foo).await?;
to_c.tx.send(Foo).await?;
}
tokio::time::delay_for(std::time::Duration::from_millis(500)).await;
Ok(())
}
#[cfg_attr(feature = "instrument", tracing::instrument(skip(from_b_to_a)))]
async fn c(mut from_b_to_a: MyChannel) -> Result<(), Box<dyn Error>> {
for _ in 0..10 {
span_context!(Span::current());
if let Some(_) = from_b_to_a.rx.recv().await {}
from_b_to_a.tx.send(Foo).await?;
}
tokio::time::delay_for(std::time::Duration::from_millis(500)).await;
Ok(())
}
}
*/