title: Dealing with concurrent requests in Meteor
body: <p>I'm dealing with a problem where a user can update a document within a specified time limit, and if he doesn't, the server will.</p>
  
  <p>The update involves incrementing a value and adding an object to an array of a document. I need to ensure that only one of the user/server updates the document. Not both.</p>
  
  <p>To ensure this happens, some checks are run to see if the document has already been updated, but there are times where the user and server run at exactly the same time and both pass the checks and then the document is updated twice.</p>
  
  <p>I've been trying many different ways of fixing this, but I haven't been able to. I tried implement a lock similar to this: <a href="http://en.wikipedia.org/wiki/Peterson%27s_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Peterson%27s_algorithm</a> to ensure that only one update will happen and the second update will fail, but I haven't been successful. Any ideas?</p>