Proposal: defer keyword

Ben Wiley therealbenwiley at gmail.com
Thu Sep 20 09:26:59 UTC 2018


Hey Ayush,

That's an interesting language feature I hadn't heard of before.

Any reason your use case couldn't be covered by a try/catch in the
synchronous case, and a promise.finally() in the async case?

Ben

Le jeu. 20 sept. 2018 05 h 21, Ayush Gupta <ayushg3112 at gmail.com> a écrit :

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180920/82271621/attachment.html>


More information about the es-discuss mailing list