Ron Buckton (2017-01-01T01:19:22.000Z)
> -----Original Message-----
> From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Isiah
> Meadows
> Sent: Saturday, December 31, 2016 8:34 AM
> To: J Decker <d3ck0r at gmail.com>
> Cc: Raul-Sebastian Mihăilă <raul.mihaila at gmail.com>; es-discuss <es-
> discuss at mozilla.org>
> Subject: Re: Resource management
> 
> Not enough. Not looking for an `await` replacement, but something closer to
> Python's `with` statement or Java's `try`-with-resources.
> Or, if you want something
> 
> Python:
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpreshin
> g.com%2F20110920%2Fthe-python-with-statement-by-
> example%2F&data=02%7C01%7Cron.buckton%40microsoft.com%7C9767f9fc
> 4f8a4e3489b608d4319ad95d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7
> C0%7C636187988525799540&sdata=BbbqX753QBWZaGwXqqmdWbX7sOvdp
> 3VADi%2FLjqpf2%2Fs%3D&reserved=0
> Java:
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.o
> racle.com%2Fjavase%2Ftutorial%2Fessential%2Fexceptions%2FtryResourceC
> lose.html&data=02%7C01%7Cron.buckton%40microsoft.com%7C9767f9fc4f8
> a4e3489b608d4319ad95d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0
> %7C636187988525799540&sdata=wVj3VjrOri80tOmnK%2Bvyoe2e7rb2Ft%2B
> wHv%2BkjOk%2FsFQ%3D&reserved=0
> 
> JavaScript's idioms tend towards Python, Java, C#, etc. in how resources are
> handled, so things like Ruby's `begin`-`ensure` wouldn't work as well (that
> was where I got my generator workaround from, actually, and as you can
> see, it's not exactly very obvious).
> -----
> 
> Isiah Meadows
> me at isiahmeadows.com

Speaking of C#, the C# variant of this is the `using` statement: https://msdn.microsoft.com/en-us/library/yh598w02.aspx

I'm not advocating `using` as a new keyword for ES, given it's not already reserved and would have ASI hazards. The Java "try-with-resources" seems to be a fairly flexible syntax, though its adoption in ES would be predicated on some well-defined heuristic for determining which method to be used, given that ES does not have interfaces (and thus no System.IDisposable or java.lang.AutoCloseable). That would likely be an existing method name, such as "return" as used in iterators today, or a built-in Symbol which could be retrofit onto %IteratorPrototype%.

Ron
forbes at lindesay.co.uk (2017-01-08T05:36:38.136Z)
Speaking of C#, the C# variant of this is the `using` statement: https://msdn.microsoft.com/en-us/library/yh598w02.aspx

I'm not advocating `using` as a new keyword for ES, given it's not already reserved and would have ASI hazards. The Java "try-with-resources" seems to be a fairly flexible syntax, though its adoption in ES would be predicated on some well-defined heuristic for determining which method to be used, given that ES does not have interfaces (and thus no System.IDisposable or java.lang.AutoCloseable). That would likely be an existing method name, such as "return" as used in iterators today, or a built-in Symbol which could be retrofit onto %IteratorPrototype%.