Hello, I wonder if there is a way to synchronize objects/methods in JavaScript in a similar way that you do it in Java. I am developing an interface for the new WebSocket in html5 and need a way to match outgoing requests with incoming responses. Therefor I'm saving the requests (with an unique id) in an array on the client side and then I iterate through the array when I receive a response looking for the matching request.
A problem is that might occur on the client side is if I have multiple timers that are making requests to the server independently of each other. If a the request function is inserting a "request-reference" into the array at the same time as the respond-listener is iterating through the array it's bound to break!
So how do I solve this problem? My initial thoughts was to simply synchronize the array as one could have done in Java (putting a lock on the object and force the other functions to wait) but I have found no syntax of how I would do this in JavaScript.