Proposal: Bind Promise Catch to Try/Catch scope

kdex kdex at kdex.de
Wed Jun 22 01:06:08 UTC 2016


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>
> 


More information about the es-discuss mailing list