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

Add async generator documentation #17529

Merged
merged 45 commits into from
Jul 16, 2022
Merged

Add async generator documentation #17529

merged 45 commits into from
Jul 16, 2022

Conversation

Josh-Cena
Copy link
Member

@Josh-Cena Josh-Cena commented Jun 22, 2022

Summary

Fix #1459
Fix #2248
Fix #2803

Continuation of #2861. Most credit goes to @DerekNonGeneric.

For now this is still a draft, only submitting because I suck at branch management and I risk accidentally deleting this branch if not published to remote while cleaning all local branches. TODOs:

(First time trying the workflow of using gh pr checkout to checkout a fork's branch and then pushing to a different forked remote. Looks like it works?)

Motivation

Supporting details

Related issues

Metadata

  • Adds a new document
  • Rewrites (or significantly expands) a document
  • Fixes a typo, bug, or other error

DerekNonGeneric and others added 22 commits June 22, 2022 12:40
Adds pages for the `AsyncGenerator` and `AsyncGeneratorFunction`
standard built-in global objects that had been missing from the
“Control abstraction objects” section.

Fixes: mdn#2803
Co-authored-by: André Jaenisch <Ryuno-Ki@users.noreply.github.com>
Co-authored-by: André Jaenisch <Ryuno-Ki@users.noreply.github.com>
Co-authored-by: André Jaenisch <Ryuno-Ki@users.noreply.github.com>
…star_/index.html

Co-authored-by: Daniel D. Beck <daniel@ddbeck.com>
This reverts commit c331788.
…atorfunction/index.html

Co-authored-by: wbamberg <will@bootbonnet.ca>
…atorfunction/index.html

Co-authored-by: wbamberg <will@bootbonnet.ca>
@Josh-Cena Josh-Cena requested a review from a team as a code owner June 22, 2022 05:01
@Josh-Cena Josh-Cena requested review from wbamberg and removed request for a team June 22, 2022 05:01
@Josh-Cena Josh-Cena marked this pull request as draft June 22, 2022 05:01
@github-actions github-actions bot added the Content:JS JavaScript docs label Jun 22, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 22, 2022

Preview URLs

Flaws

Note! 21 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/JavaScript/Reference
Title: JavaScript reference
on GitHub
Flaw count: 1

  • macros:
    • wrong xref macro used (consider changing which macro you use)

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGeneratorFunction
Title: AsyncGeneratorFunction
on GitHub
Flaw count: 1

  • broken_links:
    • Can't resolve /en-US/docs/Web/JavaScript/Guide/Iterators_and_generators

URL: /en-US/docs/Web/JavaScript/Reference/Operators/function*
Title: function* expression
on GitHub
Flaw count: 1

  • macros:
    • /en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope redirects to /en-US/docs/Web/JavaScript/Reference/Functions

External URLs

URL: /en-US/docs/Web/JavaScript/Reference
Title: JavaScript reference
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements
Title: Statements and declarations
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements/function*
Title: function*
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements/async_function*
Title: async function*
on GitHub


URL: /en-US/docs/Web/JavaScript/Reference/Statements/async_function
Title: async function
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
Title: for await...of
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements/function
Title: function declaration
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Iteration_protocols
Title: Iteration protocols
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator
Title: Symbol.asyncIterator
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGeneratorFunction
Title: AsyncGeneratorFunction
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction
Title: GeneratorFunction
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
Title: AsyncFunction
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator
Title: AsyncGenerator
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return
Title: AsyncGenerator.prototype.return()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next
Title: AsyncGenerator.prototype.next()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw
Title: AsyncGenerator.prototype.throw()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function
Title: Function() constructor
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator
Title: Generator
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next
Title: Generator.prototype.next()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Operators
Title: Expressions and operators
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Operators/function*
Title: function* expression
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Operators/async_function*
Title: async function* expression
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Operators/async_function
Title: async function expression
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Operators/function
Title: Function expression
on GitHub

No new external URLs

(this comment was updated 2022-07-16 10:49:08.770290)

@Josh-Cena
Copy link
Member Author

A lot of the examples here are directly ported from their sync counterparts and appear overly contrived. Welcoming more examples since I can't think of any async work besides database connection, file system access, and web requests. (Maybe I should make examples with fetch?)

@DerekNonGeneric
Copy link
Contributor

I would like to invite @lmammino to have a look as he recently released an iteration protocols workshop on the topic. Hopefully he would be able to spot any glaring transgressions wrt the protocols' documentation.

Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

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

I have one nit. Re-request my review when this is ready to be merged.

@Josh-Cena
Copy link
Member Author

I've slightly reworked the examples. I think async generators are not very useful without bringing some external APIs like fetch or fs.readFile, so I've changed my mind a bit and believe contrived examples are not that bad, as long as we illustrate how async generators can be used. How they are made can be in follow-up PRs if someone has better examples.

@Josh-Cena Josh-Cena requested a review from teoli2003 July 15, 2022 05:44
@ghost
Copy link

ghost commented Jul 15, 2022

I've slightly reworked the examples. I think async generators are not very useful without bringing some external APIs like fetch or fs.readFile, so I've changed my mind a bit and believe contrived examples are not that bad, as long as we illustrate how async generators can be used. How they are made can be in follow-up PRs if someone has better examples.

I suppose a more contrived example that could be made would be converting Events with callbacks to an await for..of loop over a generator of Promise<Event>s? It still is an inherently asynchronous, and a note can be left about how this can give rise to API's such as Node.js's events.once.

@Josh-Cena
Copy link
Member Author

I think the argument about tables vs. lists is well-made and deserves better attention. (It harms maintainability as well.) Shall we start a discussion?

@Josh-Cena Josh-Cena requested a review from teoli2003 July 15, 2022 07:01
Comment on lines 88 to 94
An object implements the async iterable protocol when it implements the following methods:

| Property | Value |
| ------------------- | --------------------------------------------------------------------------------------------------------------- |
| `[Symbol.asyncIterator]` | A zero-argument function that returns an object, conforming to the async iterator protocol. |

An object implements the async iterator protocol when it implements the following methods:
Copy link

Choose a reason for hiding this comment

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

The table wasn't completely removed(?)

Copy link

@ghost ghost Jul 15, 2022

Choose a reason for hiding this comment

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

Oh! iterable vs. iterator, sorry I didn't catch that; not sure if you want to remove that though, even though it is small.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about it—this one seems trivial enough.

Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

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

Let's land this \o/.

If more changes are needed, they can be in follow-ups. No need to hold this for perfection.

@teoli2003 teoli2003 merged commit 12da8f8 into mdn:main Jul 16, 2022
@Josh-Cena Josh-Cena deleted the add-async-iter branch July 16, 2022 14:59
@lmammino
Copy link

Fantastic to see this landed! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs
Projects
None yet
6 participants