kay am see
kay am see

Reputation: 988

locking in javascript for node.js

//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.

Upvotes: 1

Views: 707

Answers (1)

Jason
Jason

Reputation: 847

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

Upvotes: 2

Related Questions