I am looking for a solution for a problem in Node.js. Please help !
I have a router "find user", if user is existed in db continue do taskFunc(), else response error. But, my taskFunc() must take many time to complete, because each 30 seconds it will do a task.
I want to after check user exist, must response to client immediately, taskFunc() just run on server, if has error then throw.
router.post('/router1, function(req, res){
var username = body.username
User.find({where: {username: username}})
.then(function(_data){
if(_data){
return taskFunc()
}else{
res.status(400).end()
}
})
})
var taskFunc = function(username){
// function này thời gian xử lý mất nhiều thời gian
// vì nó cứ nghỉ khoảng 30s mới thực hiện 1 nhiệm vụ khác
}