Bug 1500735 - Update cached-iterable in Fluent to 0.3.0. r=stas
authorZibi Braniecki <zbraniecki@mozilla.com>
Mon, 22 Oct 2018 15:05:35 +0000
changeset 490698 6c8bbe5f25a750a29707105cc1d57871af9e1fae
parent 490697 23f77dfb5679f3cd4e34250c9511c8a49041a956
child 490699 af3fd0a2c2e61c263a1d252824dfdeb18162cf14
child 490755 65bfae07e0f4fdcc22bbf909ffbe92f7224f546b
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersstas
bugs1500735
milestone64.0a1
Bug 1500735 - Update cached-iterable in Fluent to 0.3.0. r=stas Differential Revision: https://phabricator.services.mozilla.com/D9350
intl/l10n/Localization.jsm
--- a/intl/l10n/Localization.jsm
+++ b/intl/l10n/Localization.jsm
@@ -67,71 +67,51 @@ class CachedAsyncIterable extends Cached
     } else if (Symbol.iterator in Object(iterable)) {
       this.iterator = iterable[Symbol.iterator]();
     } else {
       throw new TypeError("Argument must implement the iteration protocol.");
     }
   }
 
   /**
-   * Synchronous iterator over the cached elements.
-   *
-   * Return a generator object implementing the iterator protocol over the
-   * cached elements of the original (async or sync) iterable.
-   */
-  [Symbol.iterator]() {
-    const cached = this;
-    let cur = 0;
-
-    return {
-      next() {
-        if (cached.length === cur) {
-          return {value: undefined, done: true};
-        }
-        return cached[cur++];
-      },
-    };
-  }
-
-  /**
    * Asynchronous iterator caching the yielded elements.
    *
    * Elements yielded by the original iterable will be cached and available
    * synchronously. Returns an async generator object implementing the
    * iterator protocol over the elements of the original (async or sync)
    * iterable.
    */
   [Symbol.asyncIterator]() {
     const cached = this;
     let cur = 0;
 
     return {
       async next() {
         if (cached.length <= cur) {
-          cached.push(await cached.iterator.next());
+          cached.push(cached.iterator.next());
         }
         return cached[cur++];
       },
     };
   }
 
   /**
    * This method allows user to consume the next element from the iterator
    * into the cache.
    *
    * @param {number} count - number of elements to consume
    */
   async touchNext(count = 1) {
     let idx = 0;
     while (idx++ < count) {
       const last = this[this.length - 1];
-      if (last && last.done) {
+      if (last && (await last).done) {
         break;
       }
-      this.push(await this.iterator.next());
+      this.push(this.iterator.next());
     }
     // Return the last cached {value, done} object to allow the calling
     // code to decide if it needs to call touchNext again.
     return this[this.length - 1];
   }
 }
 
 /**