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

Unified Diff: lib/io.js

Issue 29340852: Issue 3993 - Implement Utils.yield() in a better way (ABP/Firefox part) (Closed)
Patch Set: Created April 26, 2016, 6:50 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
« dependencies ('K') | « dependencies ('k') | lib/utils.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/io.js
===================================================================
--- a/lib/io.js
+++ b/lib/io.js
@@ -73,40 +73,40 @@ let IO = exports.IO =
{
try
{
let processing = false;
let buffer = "";
let loaded = false;
let error = null;
- let onProgress = function(data)
+ let onProgress = function*(data)
{
let index = (processing ? -1 : Math.max(data.lastIndexOf("\n"), data.lastIndexOf("\r")));
if (index >= 0)
{
// Protect against reentrance in case the listener processes events.
processing = true;
try
{
let oldBuffer = buffer;
buffer = data.substr(index + 1);
data = data.substr(0, index + 1);
let lines = data.split(/[\r\n]+/);
lines.pop();
lines[0] = oldBuffer + lines[0];
for (let i = 0; i < lines.length; i++)
- listener.process(lines[i]);
+ yield listener.process(lines[i]);
}
finally
{
processing = false;
data = buffer;
buffer = "";
- onProgress(data);
+ yield* onProgress(data);
if (loaded)
{
loaded = false;
onSuccess();
}
if (error)
@@ -174,17 +174,17 @@ let IO = exports.IO =
let f = yield OS.File.open(file.path, {read: true});
while (true)
{
let array = yield f.read(BUFFER_SIZE);
if (!array.length)
break;
let data = decoder.decode(array, {stream: true});
- onProgress(data);
+ yield* onProgress(data);
}
yield f.close();
}.bind(this)).then(onSuccess, onError);
}
catch (e)
{
callback(e);
}
« dependencies ('K') | « dependencies ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld