smartnut007
smartnut007

Reputation: 6423

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?

Upvotes: 14

Views: 8439

Answers (1)

JGWeissman
JGWeissman

Reputation: 728

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.

Upvotes: 17

Related Questions