DEV Community

loading...

Discussion on: Best Practices for ES6 Promises

Collapse
dasdaniel profile image
Daniel P

while agree with "Synchronously settled promises are redundant and unnecessary"
dev.to/somedood/best-practices-for...

I'd just like to mention a case where I do tend to intentionally (over)use promises even in cases where they'd be flagged as redundant and unnecessary.

The use case is around API consistency, for example, if I've got a library or a class that mostly uses asynchronous function, ans then I have a function or two that are synchronous, I tend to wrap the synchronous functions in a promise, so the usage is consistent. I've found this especially useful when working with frameworks like Vue, where I can keep the usage in the component consistent. I've also gotten to the habit of choosing code readability/maintainability over performance, YMMV.

Collapse
somedood profile image
Basti Ortiz (Some Dood) Author

Yeah, I'd count this as an exception. I did mention in the article that it can be okay "for the sake of API compatibility". πŸ‘