Friday 26 April 2019

How to make sure each streams write go in right order.

Hi, here is the code of my function simplified:function writePage(request,response){ // Write opening Tags response.write(""); writeHead(request,response); writeBody(request, response); //Write closing tags response.write(""); } function writeHead(request, response){ config.baseHeadElements.forEach((element)=>{response.write(element)}); config.pages[request.url].headElements.forEach((element)=>{response.write(element)}); } function writeBody(request, response){ response.write(""); //this is mostly the part where trouble happens: config.pages[request.url].includeInBody.forEach((path)=>{ fs.createReadStream(__dirname + path).pipe(response, {end: false}); }); response.write(""); } How it is right now, each element of the arrays end up in the page, but not always in the right order. How can I ensure that I am only writing in response one thing at at time, in the good order?

Submitted April 27, 2019 at 02:23AM by tonystark027

No comments:

Post a Comment