Buffer incoming streamed data in the frontend

This commit is contained in:
James 2018-08-04 17:12:00 +10:00
parent 4d3ce45dc4
commit d53603e211
2 changed files with 11 additions and 3 deletions

View file

@ -32,11 +32,13 @@ where
Self: Sized,
{
/// Unwraps this object. See `unwrap()`.
#[inline]
fn log_unwrap(self) -> T {
self.log_expect("Failed to unwrap")
}
/// Unwraps this object, with a specified error message on failure. See `expect()`.
#[inline]
fn log_expect(self, msg: &str) -> T;
}

View file

@ -73,13 +73,19 @@ function stream_ajax(path, callback, successCallback, failCallback, data) {
}
});
var buffer = "";
req.onreadystatechange = function() {
if(req.readyState > 2) {
var newData = req.responseText.substr(req.seenBytes);
var lines = newData.split("\n");
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
buffer += newData;
var pointer;
while ((pointer = newData.indexOf("\n")) >= 0) {
var line = newData.substring(0, pointer).trim();
newData = newData.substring(pointer + 1);
if (line.length === 0) {
continue;
}