javascript - Blocking issue in Express / Node -


i got blocking issue express in node.js. currently, have code now:

router.get('/hello', function(req, res, next) {   (async ()=>{       try{           await api.connect();           let result=await api.handlesomethins();           await api.disconnect();       }catch(err){        console.log(err);       }   })();   return res.status(json(result)); }); 

there no problem above code, , use async/await synchronize heavy loading process.

then got situation below:

  • 1.usera use url connect node.js, , usera waitting responding now.
  • 2.userb connect in time, node.js can't handle userb's request immediately.
  • (note).i need send response user client(ios/android).

maybe node server got userc,d,etc... in same time. should can handle situation? child_proess? cluster? or else?

try this:

router.get('/hello', async (req, res, next) => {         let result = null;         try {               await api.connect();               result = await api.handlesomethins();               await api.disconnect();         } catch (err) {               console.log(err);         }          return res.status(json(result)); }); 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -