From ef8602084599b85edf113e2c42cb0cfaf95b0d88 Mon Sep 17 00:00:00 2001 From: jweg <jweg@informatik.uni-kiel.de> Date: Wed, 19 Jul 2017 10:36:38 +0200 Subject: [PATCH] downloader works with each alone and both together --- app.js | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index e43fc72..478e55e 100644 --- a/app.js +++ b/app.js @@ -174,7 +174,10 @@ function streamFilesToZip(){ backendContent = fs.readFileAsync(file.path); backendContent.then(function(data){ addBackendToZip(data).then(function(){ - resolve(finishedArray.push('backend finished')); + finishedArray.push('backend finished'); + if(finishedArray.length === promiseArray.length){ + resolve(zip); + } }) @@ -193,7 +196,10 @@ function streamFilesToZip(){ }).on('finish', function(){ console.log('zip in frontend:', zip); - resolve(finishedArray.push('frontend finished')); + finishedArray.push('frontend finished'); + if(finishedArray.length === promiseArray.length){ + resolve(zip); + } console.log('finishedArray in frontend:', finishedArray); @@ -213,24 +219,10 @@ function streamFilesToZip(){ }) } -function collectFilesToZip(finishedArray){ - console.log('in collectFilesToZip'); - console.log('finishedArray.length:', finishedArray.length); - console.log('promiseArray.length:', promiseArray.length); - return new Promise((resolve,reject)=> { - if(finishedArray.length === promiseArray.length){ - console.log('in resolve()'); - resolve(zip); - } - }) -} function finalizeZip(){ - return streamFilesToZip().then(function(){ - return collectFilesToZip(finishedArray).then(function(zip){ - + return streamFilesToZip().then(function(zip){ return createZip(zip) - }) }).catch(function(error) {let response = 'There was an error during your build. ' + 'Please contact "explorviz-developers-request@listserv.dfn.de" ' + -- GitLab