javascript - NodeJS Express - Want to run handler twice on single route -
i have route router.get('/generatedoc', handlerequest);
, want run handlerequest twice. can suggest me how tackle situation.
below code example.
function handlerequest(req, res, next) { (var = 0; < 2; i++) { cacheservice.clean(); pdfcontroller.generatepdfs(req, res, next); } }
it's odd thing require, can it:
function handlerequestinnards(req, res, next) { cacheservice.clean(); pdfcontroller.generatepdfs(req, res, next); } function handlerequest(req, res, next) { handlerequestinnards(req, res, function() { handlerequestinnards(req, res, next); }); }
you have more luck library bluebird can make promise , stuff like:
function handlerequest(req, res, next) { promise.all([ handlerequest(req, res), handlerequest(req, res) ]).ascallback(next); }
Comments
Post a Comment