haMzox
haMzox

Reputation: 2109

Returning a promise inside promise (JavaScript)

Is it a good practice to use promises inside a promise?
Thank you.

Upvotes: 2

Views: 1090

Answers (2)

Brian Joseph Spinos
Brian Joseph Spinos

Reputation: 2244

A cleaner way would be to chain the promises, you can create another promise inside the .then() function and return it. so that way you can chain the .then() functions, like this:

getUserPromise().then(doSomethingFunction).then(doSomethingElseFunction)

Upvotes: 1

SmashingQuasar
SmashingQuasar

Reputation: 411

There is no problem using promises inside promises, it is even required sometimes to create fully asynchronous scripts.

Upvotes: 6

Related Questions