Thanks @alexcrichton for the quick reply. Sorry for not being very clear in my 2nd question.
What I want to do is, when my Receiver receives Drain request, it’ll break the iterator and close the stream so that Sender wont be able to put any new requests in the channel. After closing, I’ll iterate over the stream again and read up all the buffered messages and exit
let commands_rx = commands_rx.or_else(|_| {
Err(io::Error::new(ErrorKind::Other, "Rx Error"))
});
#[async]
for command in commands_rx {
match command {
NetworkRequest::Drain => break,
_ => unimplemented!(),
}
}
commands_rx.close();
// tx not allowed send new requests anymore. drain
// all the buffered requests and exit
I’m facing 2 problems
P1. Unable to async iterate over stream reference ( I think this isn’t supported yet ?)
let commands_rx = commands_rx.by_ref();
#[async]
for command in commands_rx {
match command {
NetworkRequest::Drain => break,
_ => unimplemented!(),
}
}
Error
borrow may still be in use when generator yields
--> src/client/connection.rs:124:32
|
124 | let commands_rx = commands_rx.by_ref();
Q2. Getting back Receiver from OrElse<Receiver<>> to be able to apply close
Is there a way to get back Receiver stream back from the combinator?