Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Yeah, Result<Err, Val> is an awesome datatype, but it's not the norm in JS, unfortunately.
How great would Promise<Err, Val> = Future<Result<Err, Val>> be :)
Instead, they integrated with exceptions, which makes throwing inside an async function great, but makes awaiting a fallible promise pretty ugly.
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
That's the difficulty is going opposite of the norm. It really works out well when your entire application is designed that way, but can be odd when you inject it into an existing application.
Consistency across the application is more important. So I will do these things with a new app, but code in the same style as existing apps just for consistency.
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Hmm. Well, I have used function expressions to throw, so this would be an improvement.
But since we're on the subject of Exception, I'll use this opportunity to rant about Exceptions.
Unless your intent is to halt the program, an Exception should not be thrown.
If your function can result in an exception, return it. This would follow a similar pattern as Promises.
And also similar to a callback:
Example:
The benefits are:
Yeah,
Result<Err, Val>
is an awesome datatype, but it's not the norm in JS, unfortunately.How great would
Promise<Err, Val> = Future<Result<Err, Val>>
be :)Instead, they integrated with exceptions, which makes
throw
ing inside anasync
function great, but makesawait
ing a fallible promise pretty ugly.That's the difficulty is going opposite of the norm. It really works out well when your entire application is designed that way, but can be odd when you inject it into an existing application.
Consistency across the application is more important. So I will do these things with a new app, but code in the same style as existing apps just for consistency.
Look what I found.
This guy knows what up ;)