-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAsyncIterable.html
More file actions
35 lines (32 loc) · 4.85 KB
/
Copy pathAsyncIterable.html
File metadata and controls
35 lines (32 loc) · 4.85 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
<!DOCTYPE html><html><head><meta charset="utf-8"><title>AsyncIterable JavaScript API</title><meta name="description" content="Interactive API reference for the JavaScript AsyncIterable Object.
An async iterable object is any object that has a
Symbol.asyncIterator property whose value is
a function that returns an AsyncIter"><link rel="stylesheet" type="text/css" href="styles.css"><script type="text/javascript">var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23450559-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();</script></head><body><script>if (sessionStorage.collapsed === 'true') {
document.body.classList.add('members-collapsed');
}
if (localStorage.theme) {
document.body.parentElement.classList.add(localStorage.theme);
}</script><div class="topnav"><a href="/">JavaScripture</a><div class="bookmarks"><a class="bookmark contribute" href="https://github.com/nkronlage/JavaScripture">Contribute via GitHub</a> <a class="bookmark" href="/feedback">Feedback</a></div></div><div class="container"><nav class="leftnav"><div id="searchContainer"><input id="searchBox" type="text" placeholder="Search (Ctrl + S)" autocomplete="false"><div id="resultsBox" style="display:none;"></div></div><div id="apichooser"><a href="#" onclick="openApiChooser(); return false;"><div class="arrow"></div><span id="selectedsets"></span></a><div id="obscure"></div><div id="apisets"><ul></ul></div></div><div class="toc"><h2>AsyncIterable</h2><div class="navgroup"><div class="group"><a href="#InstanceIndexers">Instance Indexers</a></div></div><h2>JavaScript API</h2><div id="related-apis" class="navgroup"></div><h2>All API</h2><div id="rootObjs" class="navgroup"><span class="empty">No API set selected.</span></div></div></nav><div class="content"><h1 class="declaration"><span class="object">AsyncIterable</span> <span class="type">: <a href="/Object">Object</a></span></h1><div class="metadata"></div><div class="objectdescription"><p>An async iterable object is any object that has a <a href="/Symbol#asyncIterator"><code>Symbol.asyncIterator</code></a> property whose value is a function that returns an <a href="/AsyncIterator">AsyncIterator</a>.</p><p>You can loop over all values in an async iterable object by using a <code>for await (const value of asyncIterable) { }</code> loop.</p><p>You may create your own async iterable object by assigning the <a href="/Symbol#asyncIterator"><code>Symbol.asyncIterator</code></a> property to an async generator function (<code>async function* () {}</code>) or an object with a <a href="/AsyncIterator#next"><code>next()</code></a> method.</p><p>See <a href="/AsyncIterator">AsyncIterator</a> for more details.</p><div class="membermetadata"><a href="http://www.ecma-international.org/ecma-262/10.0/#sec-asynciterable-interface" class="spec">Spec</a></div></div><div><a name="InstanceIndexers"></a><h2>Instance Indexers</h2><div class="member"><div class="expand-members" title="Toggle showing all descriptions and examples"></div><a name="indexer_Symbol_asyncIterator"></a><div class="declaration"><span class="membername primary">this</span>[<a href="/Symbol#asyncIterator"><span class="membername">Symbol.asyncIterator</span></a>] : <a class="membertype" href="/Function">Function</a><<a class="membertype" href="/AsyncIterator">AsyncIterator</a>></div><div class="member-body"><p class="description">Returns a function that produces an AsyncIterator for this object.</p><div class="example"><div class="codePanel"><h4>Example:</h4><textarea class="code" rows="12" cols="60" wrap="off">
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));
}
</textarea><a onclick='executeExample(this.parentNode.parentNode, "AsyncIterable.undefined"); return false' href="#" class="run">Run</a></div><div class="resultsPanel"><h4>Results:</h4><div style="position: relative"><div class="errormessage" style="display: none"></div><pre class="results"> </pre></div></div></div><p></p></div></div></div><div class="bottomnav"><a href="/">home</a> <a href="/license">license</a> <a href="https://github.com/nkronlage/JavaScripture">contribute</a> <a href="/feedback">feedback</a> <a id="toggle-theme" href="#">toggle light/dark mode</a></div><div class="copyright">Copyright © JavaScripture Contributors</div></div></div></body><script src="javascripture.js"></script></html>