If you are playing with XHR, sometimes you need to wait for many small requests.
Sure, you can have separate callback for each request, but sometimes you need to wait until you load full dataset.
Of course you can use modern ways like
promise, but there aren’t supported everywhere.
My idea was very simple - just create copy of semaphore from
This example prints your IP address and your user-agent on the screen in one nice sentence.
If you need to wait for
N request, simply create
If you wish to run
N methods parallel and you wish to run maximally
M of them at once, simply create
new Semaphore(+M) and stacks them all by