Rust Async Working Group
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
      • No invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
No invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Reading club notes: AsyncIterator ###### tags: `reading-club` ## Docs * https://without.boats/blog/async-iterator/ * https://without.boats/blog/generators/ #### See also * [AsyncIterator thread in Zulip](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async/topic/AsyncIterator) Leave questions, observations, discussion topics below. --- ## Topic name: prompt # Async iterators nrc: one thin which I didn't notice for a while, but which is obvious in retrospect is that `async next` and `poll_next` are fundamentally different in that the former is a function which creates a future on each iteration and the latter is a special kind of thing which combines future-ness and iteration tmandry: Right, I didn't realize how the rest of the properties being talked about fall out from that until recently. ## Fundamental-ness tmandry: ## Other nrc: Takeaway is that things are more complex than I thought around iteration, and that generators have a bigger role than I thought, not sure a cute desugaring. nrc: Perhaps we should focus on generators ahead of stabilizing AsyncIterator, in order to have a well-informed design. # Generators ## yield from nrc: I think boats is right that using `for` is good enough (actually I think it is better since it means less syntax). Are there examples where `yield from` actually yields much better code? tmandry: Hadn't seen it before. yield from in python: https://stackoverflow.com/questions/9708902/in-practice-what-are-the-main-uses-for-the-yield-from-syntax-in-python-3-3 nrc: These confused me in python tmandry: Looks like they have some utility in working around edge cases in Python generator uses, wouldn't apply to Rust though. ## return and ? nrc: I think this is interesting because it is about combining two 'effect sugars'. There is the illusion that Result is first class and the illusion that generators are first class and its unclear how the illusions should interact. IOW, this seems like a pure human factors aspect of PL design rather than a logical/correctness aspect. I agree with Boats that generators should return `()`. But I wonder if to use `?` in a generator the generator should yield a Result/Option rather than return it? So ? desugars to `yield` rather than `return`. tmandry: Seems like they agree with you nrc: But they're saying that after the yield the iterator would stop, which I don't think it has to do. nrc: You have two kinds of iterators where something goes wrong and that's the end, and you have iterators where something can go wrong but it's not the end. tmandry: My instinct is that the "`?` finishes the current function" should hold. nrc: Suggests that yielding and returning is right. tmandry: Although I don't know how this would generalize to coroutines. nrc: Generators tend to simplify; IME coroutines tend to make code complex. But we should answer the question of whether we want coroutines. ## The `?` return question in the post tmandry: Noodling a bit.. does a generator have to yield an Option at all? Could returning from the generator be translated into `Iterator::next()` returning `None`? ..nevermind, I think that was a misreading of the post. My intuition: You want forwarding of `?` to work from within generators. ## Self references nrc: option 1 seems the only one which is feasible to me. Are there realistic use cases for self-referential iterators? I couldn't think of any when I was noodling about this ealier. tmandry: How often do we see `for x in &v`? nrc: c.f., `for x in v` ```rust for x in &v { yield x; } ``` (or `v.iter()`) there are definitely cases where I've need to write this. Maybe because I was using combinators in a particular way? nrc: Why would you write that in a generator? tmandry: Hard to say without experience writing generators :). But it feels pretty common in Rust. tmandry: Maybe the most reasonable thing for us to do is to push for people to try out non-self-referential iterators and see if it works. nrc: Also seems easy to make them self-referential in nightly later on. ---

Import from clipboard

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template is not available.
Upgrade
All
  • All
  • Team
No template found.

Create custom template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

How to use Slide mode

API Docs

Edit in VSCode

Install browser extension

Get in Touch

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Upgrade to Prime Plan

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

No updates to save
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully