Node timing data processing

scenario: when a piece of data is created successfully, it is regularly determined to modify and update the data

testModel.create({name:"a",num:2},function(err,doc){
if(doc){
setTimeout(do,gettime())
function do(){
 update
}
}
})

express framework uses mongoose to connect mongodb,. Is it feasible to use setTimeout,setInterval in the actual production environment? of course, node also has many timing modules. How do you deal with scheduled tasks like above?

Apr.05,2021

setTimeout and setInterval are possible, but not good enough.

you can write an additional UpdateTsk component that maintains an array of functions that need to be executed regularly
, such as UpdateTsk.reg (CallBack_Func) , etc., and then let the component schedule itself to call all the callback_Func in the list

.

if it is setTimeout and setInterval, there will be tens of thousands of timers in the last possible program, which has a certain impact on efficiency

Menu