If I have the following code:
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/:name', function(req, res, next) {
let name = req.params.name;
setTimeout(()=>{
res.render('index', { title: name });
},18000);
});
module.exports = router;
I open the browser and try to request this API many times with different values for name parameter in the sametime, for example:
localhost:3000/param1 , localhost:3000/param2, localhost:3000/param3
Based on the concept of call stack with JavaScript, why name in setTimeOut callback gets the same value of req.params.name
with every request. Please check the screenshot.
via Elbassel
No comments:
Post a Comment