Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/abp2blocklist.js

Issue 29501568: Issue 3673 - Use separate function to chain promises (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Created July 31, 2017, 12:28 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/abp2blocklist.js
===================================================================
--- a/lib/abp2blocklist.js
+++ b/lib/abp2blocklist.js
@@ -63,42 +63,48 @@
}
function async(callees, mapFunction)
{
if (!(Symbol.iterator in callees))
callees = [callees];
let lastPause = Date.now();
- let index = 0;
let promise = Promise.resolve();
- for (let next of callees)
+ let chain = (next, index) =>
{
- let currentIndex = index;
-
promise = promise.then(() =>
{
if (mapFunction)
- next = mapFunction(next, currentIndex);
+ next = mapFunction(next, index);
// If it has been 100ms or longer since the last call, take a pause. This
// keeps the browser from freezing up.
let now = Date.now();
if (now - lastPause >= 100)
{
lastPause = now;
return callLater(next);
}
return next();
});
+ };
- index++;
+ // We must iterate manually here, because JSHydra does not generate correct
+ // code for let..of over non-array iterables.
+ let it = callees[Symbol.iterator]();
+ for (let next = it.next(), i = 0; !next.done; next = it.next(), i++)
+ {
+ // This must be a function call, because the value of i is evaluated
+ // lazily. let inside a loop does automatically get a closure, but JSHydra
+ // translates let to var so we lose that benefit.
+ chain(next.value, i);
}
return promise;
}
function parseDomains(domains, included, excluded)
{
for (let domain in domains)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld