javascript - How can I speed up this sequence of promises? -


i have following http request handled in node server. have send list of disks response.

the code is:

diskpromise.getdiskcount(client).then(function (diskcount) {     diskpromise.getdisks(client, diskcount).then(function (disks) {         raidpromise.getraidcount(client).then(function (raidcount) {             raidpromise.getraidarrays(client, raidcount).then(function (raidarrays) {                 (i in disks) {                     disks[i].setraidinfo(raidarrays);                 }                 raidpromise.getglobalsparelist(client).then (function(sparenames) {                     (i in disks) {                         disks[i].setspareness(sparenames);                     }                     res.json(disks);                 }, function (err) {                     console.log("something (either getdiskcount, or 1 of getdisk calls) blew up", err);                     res.send(403, { error: err.tostring() });                  });             });         });     }); }); 

the promises soap calls. takes anywhere 4.5 7.0 seconds client response back.

am doing structurally wrong laying out code?

analyzing code implies trivial parallelization opportunities fetching disks, raidarrays , sparenames. performance increased

var disks = diskpromise.getdiskcount(client).then(function (diskcount) {     return diskpromise.getdisks(client, diskcount); }); var raidarrays = raidpromise.getraidcount(client).then(function (raidcount) {     return raidpromise.getraidarrays(client, raidcount); }); var sparenames = raidpromise.getglobalsparelist(client);  promise.all([disks, raidarays, sparenames]).spread(function(disks, raidarrays, sparenames) {     for(var in disks) {         disks[i].setraidinfo(raidarrays);         disks[i].setspareness(sparenames);     }     res.json(disks); }).catch(function(err) {     console.log("something (either getdiskcount, or 1 of getdisk calls) blew up", err);     res.send(403, { error: err.tostring() }); }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -