You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/12-generators-iterators/2-async-iterators-generators/article.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ let range = {
72
72
current:this.from,
73
73
last:this.to,
74
74
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
76
76
*!*
77
77
asyncnext() { // (2)
78
78
// 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`.
183
183
184
184
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.
185
185
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.
187
187
188
188
In a regular generator we'd use `result = generator.next()` to get values. In an async generator, we should add `await`, like this:
189
189
@@ -265,15 +265,15 @@ Now values come with a delay of 1 second between them.
265
265
266
266
So far we've seen simple examples, to gain basic understanding. Now let's review a real-life use case.
267
267
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.
269
269
270
270
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:
271
271
272
272
- We should make a request to URL in the form `https://api.github.com/repos/<repo>/commits`.
273
273
- It responds with a JSON of 30 commits, and also provides a link to the next page in the `Link` header.
274
274
- Then we can use that link for the next request, to get more commits, and so on.
275
275
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:
277
277
278
278
```js
279
279
let repo = 'javascript-tutorial/en.javascript.info'; // GitHub repository to get commits from
0 commit comments