简体   繁体   中英

How can I check if a global variable that defined in Node.js if it's not changing after seconds

I wrote an app in nodejs but having logic problem with variable. I'm looking for help with this issue.

Well, i have a global integer variable named "global_something" I need a function that check if "global_something" not changing after 1000ms or 2000ms

How i can do that ?

Thanks!

You have to make 2 variable for that

var original_global = 'Test';
var copy_original_global; // save this field in database or json file for compare  

setInterval(()=>{
  if(!copy_original_global){
      copy_original_global = original_global;
       return
 } 
 if(original_global != copy_original_global){
  console.log('Changed')
 }
}, 3000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM