Bug 1500735 - Update cached-iterable in Fluent to 0.3.0. r=stas
Differential Revision:
https://phabricator.services.mozilla.com/D9350
--- 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];
}
}
/**