Skip to content
Advertisement

How can I resolve or reject a promise based on a another promise?

JavaScript

anotherPromiseFunction() returns a promise. normally inside a .then() I can return a promise to make the then() wait for that promise to finish, but how do I do it when creating a promise?

Am I supposed to do this:

JavaScript

That seems wrong…

Advertisement

Answer

You likely do not need the new Promise. The cases for “module exists” and “processor exists” can be handled separately, and then you can just return the call to anotherPromiseFunction after them:

JavaScript

If the enclosing function is an async function, you can just throw the errors instead:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement