Async Bi-directional Pipe
sync example:
```rust use anyhow::{Result,ensure}; use bidirectionalpipe::sync::pipe; use tokio::task::JoinHandle;
async fn main()->Result<()> {
let (left,right)=pipe();
let join:JoinHandle } ``` unsync example:
```rust
use anyhow::{Result,ensure};
use std::time::Instant;
use bidirectionalpipe::unsync::pipe;
use tokio::task::JoinHandle; async fn main()->Result<()> {
let single_runtime=tokio::task::LocalSet::new();
let (left,right)=pipe(); } ```loop {
if let Ok(v)=left.recv().await{
left.send(v+1);
}else {
break;
}
}
join.await??;
Ok(())
[tokio::main]
let res:Result<()>= single_runtime.run_until(async move{
let join:JoinHandle<Result<()>>= tokio::task::spawn_local(async move{
for i in 0..1000000 {
right.send(i);
let ok=right.recv().await?;
ensure!(ok==i+1,"left return v error!!")
}
Ok(())
});
let start=Instant::now();
loop {
if let Ok(v)=left.recv().await{
left.send(v+1);
}else {
break;
}
}
println!("time {}ms",start.elapsed().as_millis());
join.await??;
Ok(())
}).await;
res?;
Ok(())