Skip to content
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

Update the book tutorial to use async_std channels #398

Open
yoshuawuyts opened this issue Oct 28, 2019 · 3 comments
Open

Update the book tutorial to use async_std channels #398

yoshuawuyts opened this issue Oct 28, 2019 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@yoshuawuyts
Copy link
Contributor

yoshuawuyts commented Oct 28, 2019

With #380 landed, we should update the tutorial to use them. This would remove the final dependency on futures-rs (and importantly: Sink) which should be a big step up in terms of usability.

Also we should consider moving from select! {} to Stream::merge. From chat with @skade we've figured out how to "send a close message after a stream has been exhausted":

enum EventKind {
    Event(/* event_type */),
    Shutdown,
}

let events = events.map(|ev| EventKind::Event(ev)).join(stream::once(EventKind::Shutdown));
let shutdown = shutdown.map(|e| EventKind::Event(e));
let s = events.merge(shutdown);

while let Some(event) = s.next().await {
    match event {
        EventKind::Event(ev) => /* handle event */,
        EventKind::Shutdown => /* handle shutdown */,
    }
}

@skade I'm assigning this to you as you've been working on updating this recently. Feel free to unassign yourself if you don't think you'll have bandwidth. Thanks!

edit: this would resolve #105 and #13

@yoshuawuyts yoshuawuyts added the documentation Improvements or additions to documentation label Oct 28, 2019
@matklad
Copy link
Member

matklad commented Oct 29, 2019

cc me: I am slightly worried about introduction of explicit Shutdown messages, as opposed to just exhausting the stream. I wan to say that I want to port the tutorial myself, but I am in the middle of big refactoring of rust-analyzer right now. I'd be interested in reviewing the update PR!

@skade
Copy link
Collaborator

skade commented Oct 30, 2019

See #419 for a draft

@matklad
Copy link
Member

matklad commented Oct 30, 2019

Figured out a way to get rid of match event { Shutdown => } smell by introducing a hof which nips a stream based on a side-channel: #419 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants