Skip to content

Conversation

@rklaehn
Copy link
Collaborator

@rklaehn rklaehn commented Oct 8, 2025

mpsc::Receiver::recv returns a Result<Option, RecvError>. RecvError has a case SenderClosed. So we have 2 different ways to report that the remote has closed the sender normally. Ok(None) and Err(RecvError::SenderClosed). This is confusing. SenderClosed isn't really an error, it is just what you get if the other side closes the stream.

So this PR creates separate RecvError for oneshot and mpsc.

In oneshot we still need the SenderClosed case since we expect exactly 1 item, and therefore the receiver being closed before that item is an error.

In mpsc we remove the SenderClosed error and just report Ok(None) in that case.

rklaehn added 14 commits October 6, 2025 12:34
…and oneshot::Sender

Implement mao, filter_map and filter for mpsc::Receiver

oneshot::Receiver is a future, so you can just do this yourself using FutureExt.
this makes irpc::channel::mpsc::* a generic channel that can also be used for non-serializable msgs.

Especially when mapping you might not want intermediate map results ot be serializable!
it was not exported anyway, so the resulting future was anonymous all th etime.
In mpsc error, SenderClosed is just normal termination and should be modeled as returning None.
@rklaehn rklaehn requested a review from Frando October 8, 2025 08:51
@rklaehn rklaehn marked this pull request as ready for review October 8, 2025 09:28
@rklaehn rklaehn changed the base branch from main to filter_map October 8, 2025 09:28
src/lib.rs Outdated
};
let fut =
async move {
let size = read.read_varint_u64().await?.ok_or(oneshot::RecvError::Io(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove the oneshot::RecvError::Io I think because it impls From<io::Error>

Copy link
Member

@Frando Frando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Base automatically changed from filter_map to main October 8, 2025 10:58
@rklaehn rklaehn merged commit 2cdc1a0 into main Oct 8, 2025
16 checks passed
@rklaehn rklaehn deleted the modify-error branch October 8, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants