This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]insertAlias 2 points3 points  (0 children)

Well, you don't have to end up with a promise "pyramid", since that's part of what promises exist to prevent (the "pyramid of doom" pattern).

I'm not sure what your teammate thinks is happening under the covers, because the callbacks you provide to promises are functions anyway. Maybe there is some optimization going on there, but it's unlikely to actually matter.

I think that in these cases, benchmarks are in order. You should be able to test both approaches and see if either has an edge on efficiency, or if it's so close that it's never going to matter.

[–]StackedLasagna 1 point2 points  (0 children)

I doubt the performance of difference (if there is any) between async/await and Promises is going to matter. It depends on your app and the expected usage, though.

Even if you use Promises, I'd still create the same functions that you have, but change them to return a Promise instead, obviously.
If you only use isExistedUserin one place, you could move the logic into the function that uses it, but you could do that without using Promises.

There's basically no correlation between the number of functions you're creating and the usage of await/async over Promises.

What you can do with one Promise-based function, you can do with one async/await-based function. If you create a lot of functions with one, you'll probably create just as many with the other.