I was wondering whenever exists a solution to perform synchronization in JavaScript code. For example I have the following case: I\'m trying to cache some response values from A
First, it's important to know that all current JS implementations are single-threaded, therefore we are not discussing race-conditions and synchronizing in the context it is usually used.
As a side note, browsers are now introducing worker threads which will allow concurrency in JS, but for now this is not the case.
Anyway, you still are facing issues with what data you are expecting to receive back form asynchronous calls and you have no guarantee as to the order you will receive things.
JS gives you a very nice solution to this with callbacks. For each asynchronous event you will be sending, attach a proper callback function to it, which will handle the event properly. Synchronization, in the way you mean it, should be happening there.