DEV Community

Discussion on: Making Await More Functional in JavaScript

Collapse
 
seangwright profile image
Sean G. Wright

I like the Option pattern here but if saveUser throws, fa won't catch it because it hasn't been called yet. This requires saveUser to contain try/catch logic.

Could this be resolved by fa taking a function as a param, instead?

Collapse
 
craigmichaelmartin profile image
craig martin

Hm? fa takes a promise, so it's all good. In the example, saveUser is returning a promise - no try/catch necessary there. You can check out the source (12 lines) and the tests to see examples github.com/craigmichaelmartin/fawait

Collapse
 
seangwright profile image
Sean G. Wright

Derp! Yup, I forgot it takes a promise, even when it was shown right above saveUser returns a promise :)

Nice utility 👍