Search code examples
javascriptjqueryasynchronouses6-promise

What is the vanilla ES6 equivalent of jQuery's $.when() for promises?


What is the non-jQuery equivalent of $.when() for regular promises? If there is one. If not, how might one implement it? I looked at the jQuery source to get an idea, and it seems manageable, but I'd rather not write it myself if there exists a standard implementation already.


Solution

  • Promise.all() is what you're seeking.

    Promise.all([
      promise1,
      promise2
    ]).then(/* do something */);
    

    Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all