aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/global_objects/symbol/asynciterator
diff options
context:
space:
mode:
Diffstat (limited to 'files/fr/web/javascript/reference/global_objects/symbol/asynciterator')
-rw-r--r--files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html82
1 files changed, 82 insertions, 0 deletions
diff --git a/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html b/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html
new file mode 100644
index 0000000000..0d28cc276d
--- /dev/null
+++ b/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html
@@ -0,0 +1,82 @@
+---
+title: Symbol.asyncIterator
+slug: Web/JavaScript/Reference/Objets_globaux/Symbol/asyncIterator
+tags:
+ - ECMAScript 2018
+ - JavaScript
+ - Propriété
+ - Reference
+ - Symbole
+translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator
+---
+<div>{{JSRef}}</div>
+
+<p>Le symbole connu <code><strong>Symbol.asyncIterator</strong></code> définit l'itérateur asynchrone par défaut d'un objet. Si cette propriété est définie sur un objet, celui-ci est un itérable asynchrone et peut être utilisé avec une boucle <code><a href="/fr/docs/Web/JavaScript/Reference/Instructions/for-await...of">for await...of</a></code>.</p>
+
+<p class="hidden">Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuer à ces exemples, n'hésitez pas à cloner <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> et à envoyer une <em>pull request</em> !</p>
+
+<p>{{js_property_attributes(0,0,0)}}</p>
+
+<h2 id="Description">Description</h2>
+
+<p>Le symbole <code>Symbol.asyncIterator</code> est un symbole natif utilisé pour accéder à la méthode <code>@@asyncIterator</code> d'un objet. Pour qu'un objet soit un itérable asynchrone, il doit avoir une clé <code>Symbol.asyncIterator</code>.</p>
+
+<h2 id="Exemples">Exemples</h2>
+
+<h3 id="Itérable_asynchrone_personnalisé">Itérable asynchrone personnalisé</h3>
+
+<p>Il est possible de définir son propre itérable en définissant la propriété <code>[Symbol.asyncIterator]</code> d'un objet :</p>
+
+<pre class="brush: js">const myAsyncIterable = new Object();
+myAsyncIterable[Symbol.asyncIterator] = async function*() {
+ yield "coucou";
+ yield "l'itération";
+ yield "asynchrone !";
+};
+
+(async () =&gt; {
+ for await (const x of myAsyncIterable) {
+ console.log(x);
+ // expected output:
+ // "coucou"
+ // "l'itération"
+ // "asynchrone !"
+ }
+})();
+</pre>
+
+<h3 id="Itérables_asynchrones_natifs">Itérables asynchrones natifs</h3>
+
+<p>Il n'existe actuellement pas d'objets JavaScript natifs qui possèdent la clé <code>[Symbol.asyncIterator]</code> par défaut. Toutefois, les flux (<em>Streams</em>) WHATWG pourraient devenir les premiers objets natifs itérables asynchrones.</p>
+
+<h2 id="Spécifications">Spécifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Spécification</th>
+ <th scope="col">État</th>
+ <th scope="col">Commentaires</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ES2018', '#sec-symbol.asynciterator', 'Symbol.asyncIterator')}}</td>
+ <td>{{Spec2('ES2018')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
+
+<div class="hidden">Le tableau de compatibilité de cette page a été généré à partir de données structurées. Si vous souhaitez contribuer à ces données, n'hésitez pas à consulter <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> et à nous envoyer une <em>pull request</em>.</div>
+
+<p>{{compat("javascript.builtins.Symbol.asyncIterator")}}</p>
+
+<h2 id="Voir_aussi">Voir aussi</h2>
+
+<ul>
+ <li><a href="/fr/docs/Web/JavaScript/Reference/Les_protocoles_iteration">Les protocoles d'itération</a></li>
+ <li><code><a href="/fr/docs/Web/JavaScript/Reference/Instructions/for-await...of">for await... of</a></code></li>
+</ul>