Replies: 2 comments
-
My 2 cents on this topic are that the current API is fine as it is.
Admittedly, designs like these are not so easy to see and it also took me a while to wrap my head around that. I gets especially tricky if I think the hard part here is the knowledge about how to build concurrent systems in Rust that don't trick around This might be a bit of a long-shot from the original discussion topic but I feel like it is actually connected. In the end, the desire behind exposing the channel was to integrate with the remaining part of the application built around async/await. |
Beta Was this translation helpful? Give feedback.
-
I do also believe that the code as it is encourages good programming practices. I'm not against escape hatches, as sometimes they're extremely useful, but in my opinion the idiomatic way should remain to pass back the response to the behaviour. |
Beta Was this translation helpful? Give feedback.
-
It has been brought up in #1639, that it would be nice if the API of
libp2p-request-response
would offerResponseChannel::send(response)
instead ofRequestResponse::send_response(channel, response)
. The advantage is obviously that one does not need to have access to theRequestResponse
behaviour in order to send responses, i.e. one can distribute theResponseChannel
s received from inbound requests in the application and send responses "from anywhere". SinceRequestResponse::send_response
currently needs no access to any state of theRequestResponse
behaviour (contrary toRequestResponse::send_request
), this would be easy to do. The main concern is one of future-proofness, i.e. ifRequestResponse::send_response
should later need access toRequestResponse
state, the change may potentially be not backward-compatible or at least require more effort (i.e. it may be possible to do such a change without breaking the public API if theResponseChannel
that the behaviour exposes contains anotheroneshot
channel whose receiving end is kept by theRequestResponse
behaviour; once resolved (i.e. the response is send) it would forward the response to theoneshot
channel whose receiving end is in theInboundUpgrade
). Thus, if we change the API to offerResponseChannel::send(response)
and later need access toRequestResponse
state, that would require some more indirection or a breaking change to the API. This issue is about weighing the pros/cons of providingResponseChannel::send(response)
vs the loss of flexibility in how sending of responses is implemented internally and gathering opinions on this matter.Beta Was this translation helpful? Give feedback.
All reactions