I like the idea of mpsc, having independent threads and have data flowing between them (when the data actually needs to go one way).
This feature saves us from using Mutex, for the cost of a little memory.
In some situations, I want to request some data from anther thread so i would like to have a two way pipe, similer to the http request response pattern, not between IP address, but between threads,
I am pretty sure it has some term and some crate I don't have the handle to it.
something like the following
let {server,client}=reqres::channel()
let client1=client.clone()
let client2=client.clone()
thread::spawn(move ||{
for req in server {
req.send(req.read().to_uppercase)
}
})
thread::spawn(move ||{
client1.send("hello")
println!("{}",client1.recv().unwrap())//HELLO
})
thread::spawn(move ||{
client2.send("hello")
println!("{}",client2.recv().unwrap())//HELLO
})
Oh no, I was thinking a convenience wrapper around the "reply channel" pattern I was talking about, where channel.call(foo) is a convenience method which would send foo and wait for a reply. Alternatively one could call channel.send(foo) which would return the reply channel to recv on later.