-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathasynciterable.jsdoc
More file actions
52 lines (41 loc) · 1.24 KB
/
Copy pathasynciterable.jsdoc
File metadata and controls
52 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
AsyncIterable : Object
<p>
An async iterable object is any object that has a
%%/Symbol#asyncIterator|**Symbol.asyncIterator**%% property whose value is
a function that returns an %%/AsyncIterator|AsyncIterator%%.
</p>
<p>
You can loop over all values in an async iterable object by using a
**for await (const value of asyncIterable) { }** loop.
</p>
<p>
You may create your own async iterable object by assigning the
%%/Symbol#asyncIterator|**Symbol.asyncIterator**%% property to an
async generator function (**async function* () {}**) or an object with a
%%/AsyncIterator#next|**next()**%% method.
</p>
<p>
See %%/AsyncIterator|AsyncIterator%% for more details.
</p>
Spec:
http://www.ecma-international.org/ecma-262/10.0/#sec-asynciterable-interface
----
instance[Symbol.asyncIterator] : Function<AsyncIterator>
Returns a function that produces an AsyncIterator for this object.
<example>
class UriFetcher {
constructor(uris) {
this._uris = uris;
}
async *[Symbol.asyncIterator]() {
for (const uri of this._uris) {
const response = await fetch(uri);
yield await response.text();
}
}
}
const fetcher = new UriFetcher(['/', '/Array']);
for await (const page of fetcher) {
console.log(page.substring(0, 100));
}
</example>