Skip to content

Feature : recv and send methods for the request_reply sockets that takes a mutable reference of the RequestReceiver and the RequestSender #41

@eldoccc

Description

@eldoccc

I believe recv(mut self) and send(mut self, mut msg: Multipart) in the request_reply sockets were designed to take self instead of &mut self so you cannot make multiple send before getting the reply and rcv before sending the reply.
However in the case of tokio::select! inside of a loop :

let (tx,rx) = mpsc::channel(64);

loop {
            tokio::select! {
                _  = rx.recv() => {}
                _  = request_receiver.recv() => {}
            }
        }

because recv() consumes self, the compiler won't allow for it to be used in this case.

A barbaric solution would be to spawn a task containing the recv() and use channels to communicate back and forth with the select!, however i'd rather have an appropriate method for this case.

Without wanting to alter the current structure, a quick fix for me was the create a struct RequestReply contaning both the send(&mut self, mut msg: Multipart) and the recv(&mut self) methods in the cloned repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions