Proposal: defer keyword

Isiah Meadows isiahmeadows at gmail.com
Thu Sep 20 16:48:45 UTC 2018


Could you chime in with this here as an alternative?
https://github.com/tc39/proposal-using-statement

-----

Isiah Meadows
contact at isiahmeadows.com
www.isiahmeadows.com
On Thu, Sep 20, 2018 at 7:36 AM kdex <kdex at kdex.de> wrote:
>
> So, when is a function supposed to be invoked when `defer`red in a generator?
>
> On Thursday, September 20, 2018 11:21:06 AM CEST Ayush Gupta wrote:
> > Hi,
> >
> > I would like to propose a `defer` keyword(or something else  as the keyword
> > name) which would allow   us to "defer" a function which will be executed
> > once the current function either returns or throws.
> >
> > The idea for this is taken from the Go programming language.
> >
> > It would allow us to perform cleanup activities in a function which has
> > multiple branches in a single place.
> >
> > For example, a sample server side code can look  like:
> >
> > ```  js
> > function doSomeDbWork() {
> >     const connection = databasepool.getConnection();
> >     defer function () { connection.release(); } // function would be called
> > no matter when/if the function returns or throws
> >     //   do your work
> > }
> > ```
> >
> > Regards
> > Ayush Gupta_______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list