Skip to content

Revisit choice for channel senders to use Result #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aturon opened this issue Nov 2, 2016 · 10 comments
Closed

Revisit choice for channel senders to use Result #225

aturon opened this issue Nov 2, 2016 · 10 comments

Comments

@aturon
Copy link
Member

aturon commented Nov 2, 2016

The fact that senders use Result has always struck me as a bit odd, and with the introduction of Sink, makes channels somewhat finicky to compose. I'd like to revisit whether this is the right choice to bake in by default, vs requiring a "flattening" transformation in the cases where you do want to use Result.

(Another, more minor strike against this choice is the inconsistency with oneshot, which is on its way to being more of a channel-like abstraction.)

@aturon aturon added this to the 0.2 release milestone Nov 2, 2016
@alexcrichton
Copy link
Member

Yeah I'd kinda prefer to not send results as well, but do we have another error type for the channel? Oneshots have a concrete error type of "disconnected", but for streams that's done through ending the stream.

Of course it's possible that we could say that the error type is just never generated... (e.g. it's just a generic w/ a phantomdata)

@aturon
Copy link
Member Author

aturon commented Nov 3, 2016

Right, or (), or ! once that's stable.

@alexcrichton
Copy link
Member

I'd feel kinda bad going to () specifically because it's never actually produced, and ! I'd be hesitant for as it's just not stable yet and will take awhile to propagate...

In the meantime I feel like it's better to make use of the error type and send results than to hardwire it to a generic or (), though

@aturon
Copy link
Member Author

aturon commented Nov 3, 2016

In the meantime I feel like it's better to make use of the error type and send results than to hardwire it to a generic or (), though

That doesn't really make sense to me. Just because the error type is there doesn't mean we have to use it, and the Result situation makes channel usage more complicated for clients that don't need it (which I suspect is the common case).

Note that we have plenty of examples of unused errors: consider Read/Write on any in-memory data structure.

I do agree that making it generic over the error is going to be a pain, but we can provide a ChannelError newtype which wraps () for now, and will wrap ! later on.

@carllerche
Copy link
Member

This probably relates to #206

@aturon
Copy link
Member Author

aturon commented Nov 3, 2016

Another related issue: the choice of stream::iter to require Result.

@carllerche
Copy link
Member

carllerche commented Nov 3, 2016

IMO, the error type of the stream should be used to indicate a scenario where the stream was terminated abruptly due to an error condition.

In some cases, it may be that it is impossible for a stream to terminate abruptly, in which case ! would be appropriate.

@alexcrichton
Copy link
Member

Ok well I saw at least one location where we may want enum Void in the Sink PR, so we could perhaps just reuse that here for the error type (I'd prefer something uninhabited to ())

@alexcrichton
Copy link
Member

And yes this is related to #206 and yes stream::iter would likely change as well...

@alexcrichton
Copy link
Member

SPSC is removed, MPSC includes this change, and the old channels are deprecated, so closing.

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

No branches or pull requests

3 participants