Proposal: Bind Promise Catch to Try/Catch scope

Todd Hubers todd.hubers at alivate.com.au
Wed Jun 22 01:15:29 UTC 2016


1. Whether you await or not, the try scope's catch callback [TSCC] should
still be captured.
2. If there is no use of Promise (for coders own design reasons) the try
scope's catch callback [TSCC] should be available

On 22 June 2016 at 11:06, kdex <kdex at kdex.de> wrote:

> Why not just transform callback-based APIs into `Promise`s and use
> (presumably ES2017)
> `await`/`async` (which *does* support `try`/`catch`)?
>
> e. g.:
> ```js
> try {
>   await curl("example.com");
>   /* success */
> }
> catch (e) {
>   /* error */
> }
> ```
>
> On Mittwoch, 22. Juni 2016 10:55:24 CEST Todd Hubers wrote:
> > see http://blog.alivate.com.au/callback-api-for-es6/
> >
> > Problem: Try blocks don’t work in a callback world.
> >
> > Proposed solution:
> >
> >    - Implement API: window.callback.getCatch() - which is a callback to
> the
> >    parent catch block scope.
> >       - Ie. While the try scope is entered, internally the catch handler
> is
> >       stored as a function
> (window.callback.activeCatch.push(thisCatch)). When
> >       the try scope is left, that value is popped.
> >    - Promise: defaults its catch callback to whatever getCatch() returns
> >
> > I'm sure there are plenty more details that could be covered and
> "Callback
> > API" and "getCatch" are totally open to debate. But I hope you get the
> gist
> > of it efficiently with this email.
> >
> > Regards,
> >
> > Todd Hubers (BBIT Hons)
> > Software Engineer
> >
> > Contact <http://alivate.com.au/todd/> | Availability
> > <
> https://www.google.com/calendar/embed?src=todd.hubers@alivate.com.au&ctz=Australia/Sydney
> >
> >
> >
> >
> > Sent with MailTrack
> > <
> https://mailtrack.io/install?source=signature&lang=en&referral=todd.hubers@alivate.com.au&idSignature=22
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160622/d1c70bce/attachment.html>


More information about the es-discuss mailing list