On Mon, Dec 16, 2013 at 1:47 AM, Tomas Mikula <tomas.mik...@gmail.com> wrote: > On Mon, Dec 16, 2013 at 1:07 AM, Scott Palmer <swpal...@gmail.com> wrote: >> Interesting, no worse than John's pattern though. >> I thought of using a try/finally to make sure release was called and that >> naturally lead to thinking of try-with-resources, where the "resource" in >> this case is a binding of some sort (or a wrapper around a binding) that is >> invalidated on close() if needed. > > That is an interesting idea. I didn't intend blockWhile() to be safe > with respect to exceptions, but merely > > void blockWhile(Runnable r) { > block(); > r.run(); > release(); > } > > Enhancement you are suggesting could be fleshed out as block() > returning an AutoCloseable and the usage would be > > try(AutoCloseable a = relaxedArea.block()) { > obj.setWidth(w); > obj.setHeight(h); > }
OK, done. I implemented both: 1. added the blockWhile() method; 2. made bindings AutoCloseable, and block() returns `this`. Tomas