Skip to content

Commit f6452cb

Browse files
authored
Update article.md
1 parent e9e4801 commit f6452cb

File tree

1 file changed

+4
-4
lines changed
  • 1-js/12-generators-iterators/2-async-iterators-generators

1 file changed

+4
-4
lines changed

Diff for: 1-js/12-generators-iterators/2-async-iterators-generators/article.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let range = {
7272
current: this.from,
7373
last: this.to,
7474

75-
// next() is called on each iteration by the for..of loop
75+
// next() is called on each iteration by the for await..of loop
7676
*!*
7777
async next() { // (2)
7878
// it should return the value as an object {done:.., value :...}
@@ -183,7 +183,7 @@ Now we have the async generator, iterable with `for await...of`.
183183
184184
It's indeed very simple. We add the `async` keyword, and the generator now can use `await` inside of it, rely on promises and other async functions.
185185
186-
Technically, another the difference of an async generator is that its `generator.next()` method is now asynchronous also, it returns promises.
186+
Technically, another difference of an async generator is that its `generator.next()` method is now asynchronous also, it returns promises.
187187
188188
In a regular generator we'd use `result = generator.next()` to get values. In an async generator, we should add `await`, like this:
189189
@@ -265,15 +265,15 @@ Now values come with a delay of 1 second between them.
265265
266266
So far we've seen simple examples, to gain basic understanding. Now let's review a real-life use case.
267267
268-
There are many online services that deliver paginated data. For instance, when we need a list of users, a request returns a pre-defined count (e.g. 100 users) - "one page", and provides an URL to the next page.
268+
There are many online services that deliver paginated data. For instance, when we need a list of users, a request returns a pre-defined count (e.g. 100 users) - "one page", and provides a URL to the next page.
269269
270270
The pattern is very common, it's not about users, but just about anything. For instance, GitHub allows to retrieve commits in the same, paginated fashion:
271271
272272
- We should make a request to URL in the form `https://api.github.com/repos/<repo>/commits`.
273273
- It responds with a JSON of 30 commits, and also provides a link to the next page in the `Link` header.
274274
- Then we can use that link for the next request, to get more commits, and so on.
275275
276-
But we'd like to have is a simpler API: an iterable object with commits, so that we could go over them like this:
276+
But we'd like to have a simpler API: an iterable object with commits, so that we could go over them like this:
277277
278278
```js
279279
let repo = 'javascript-tutorial/en.javascript.info'; // GitHub repository to get commits from

0 commit comments

Comments
 (0)