Idiomatically handling pre-conditions with ES6 Promises

后端 未结 1 1286
借酒劲吻你
借酒劲吻你 2020-12-11 20:33

I am new to ES6 Promises and have been doing research. I have some code executing in NodeJS that does some async work, but I have a few pre-conditions that must be checked f

相关标签:
1条回答
  • 2020-12-11 21:24

    I'm not certain I understand the intent of Promise.reject(), but it seems to fit the bill here

    You've understood it correctly. It's explicitly made for use cases such as this. Go for it, it is the best practice.

    The advantage of Option 2 is that it works much cleaner with APIs that already do return promises (think return externalLibrary.doSomethingAsync(data)), and has less chance to fall for the Promise constructor antipattern.

    0 讨论(0)
提交回复
热议问题