Skip to content

Conversation

@ADD-SP
Copy link
Member

@ADD-SP ADD-SP commented Sep 7, 2025

Motivation

I noticed the example of poll_proceed is a bit long while thinking about the #7565 (comment).

I always prefer a short example because it helps people like me to grasp the basic usage in 10 seconds.

image

@ADD-SP ADD-SP added T-docs Topic: documentation A-tokio Area: The main tokio crate M-coop Module: tokio/coop labels Sep 7, 2025
@ADD-SP ADD-SP force-pushed the add_sp/task-improve-coop-example branch from 7f9ff77 to 016a574 Compare September 7, 2025 09:37
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

This is a good example, thanks.

@Darksonn
Copy link
Contributor

Darksonn commented Sep 8, 2025

Actually, I'm not so sure about the example. The branch returns Poll::Ready and we generally always .made_progress() when we return Ready. The other branch writes to the buffer but returns Pending, but if you wrote anything you should return Ready.

@ADD-SP
Copy link
Member Author

ADD-SP commented Sep 8, 2025

Actually, I'm not so sure about the example. The branch returns Poll::Ready and we generally always .made_progress() when we return Ready. The other branch writes to the buffer but returns Pending, but if you wrote anything you should return Ready.

Ah, bad mistake, I have fixed it.

@ADD-SP
Copy link
Member Author

ADD-SP commented Sep 8, 2025

I considered adding a reasonable Pending case, but I didn't find a reasonable one, so I chose to return Poll::Ready unconditionally.

@Darksonn
Copy link
Contributor

Darksonn commented Sep 8, 2025

What about having the example be "add coop to the futures mpsc channel"?

@ADD-SP
Copy link
Member Author

ADD-SP commented Sep 8, 2025

What about having the example be "add coop to the futures mpsc channel"?

Looks still straightforward. I chose to not include the UnboundedSender, as the Sink requires too many methods to be implemented, which makes the example too long.

image

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

One last nit. Feel free to merge after this.

@ADD-SP ADD-SP merged commit 024bd60 into tokio-rs:master Sep 10, 2025
91 checks passed
@ADD-SP ADD-SP deleted the add_sp/task-improve-coop-example branch September 10, 2025 12:57
@Darksonn Darksonn mentioned this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-coop Module: tokio/coop T-docs Topic: documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants