Asynchronous semaphore for Javascript