Remove async/await from lib

This commit is contained in:
Emil Tholin
2018-01-05 23:19:40 +01:00
parent ee94f355d5
commit 2b3472b1b1
2 changed files with 79 additions and 59 deletions

View File

@@ -31,10 +31,14 @@ function create_templates() {
return key in data ? data[key] : '';
});
},
stream: async (res, data) => {
stream: (res, data) => {
let i = 0;
do {
function stream_inner() {
if (i >= template.length) {
return;
}
const start = template.indexOf('%sapper', i);
if (start === -1) {
@@ -53,9 +57,14 @@ function create_templates() {
const match = /sapper\.(\w+)/.exec(tag);
if (!match || !(match[1] in data)) throw new Error(`Bad template`); // TODO ditto
res.write(await data[match[1]]);
i = end + 1;
} while (i < template.length);
return Promise.resolve(data[match[1]]).then(datamatch => {
res.write(datamatch);
i = end + 1;
return stream_inner();
});
}
return Promise.resolve().then(stream_inner);
}
};
})