1
//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:

  1. I update my newsItems object by getting value from some news site.
  2. 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.

1

1 Answer 1

2

If you are running Node.js as your server, you don't need any lock. It's a single-thread environment.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.