On Wed, Apr 26, 2017 at 10:47 AM, Юрий Соколов <funny.fal...@gmail.com> wrote: > You are not quite right. Sometimes there is scope dependency between Lock > and Unlock, ie Unlock happens not at function exit, but is triggered > asynchronously by some condition.
If you can stomach the overhead of yet another stack frame allocation you can always wrap your lock/unlock (or file close or whatever) and logic in an anonymous closure. This of course may not be appropriate for all situations, and isn't especially nice looking; anytime I find myself doing this my general reaction is that I need to refactor so that it's not necessary. > func() { > m.Lock() > defer m.Unlock() > > // Do some stuff > }() > // … > // outer function end > } —Sam -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.