Handling a large number of promises in JavaScript