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); |
} |