Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to achieve atomic operations ( Concurrency model ) in JavaScript?

Say, I want to increment a counter every time I get an ajax response. I don't know about the concurrency model with JavaScript async events. Any thoughts?

like image 625
smartnut007 Avatar asked Aug 11 '11 18:08

smartnut007


1 Answers

Within a browser, there is only ever one javascript thread running at a time.

Concurrency issues are possible in that while an ajax response is pending, javascript may run in response to an unrelated event. But you are safe if you do not start an operation intended to be atomic before an ajax call and finish it in the response handler.

like image 162
JGWeissman Avatar answered Oct 23 '22 06:10

JGWeissman