//News object var newsItem = function(heading, type, time, details, ...) { this.heading = heading; this.type = type; this.time = time; this.details = details; .... }; // array of all newsItem objects var newsItems = [news1, news2, news....]; I do two things with my above node.js server side code:
- I update my newsItems object by getting value from some news site.
- I create html out of newsItems object to show it on UI.
Question:
How do I make sure that when I am updating my newsItems object I dont use it to create html.
Since this is multi threaded, one thread serving a request and background thread updating the object from the news site. I need some kind of locking here in javascript. I am running into race condition here.
Thanks a lot.