On Saturday, October 22, 2011 at 1:35 AM, Michael Johnston wrote: > When I need to get a queue-protected result into a local in code that is > concurrent (so I can't use an ivar) is a pointer the best (only) way to get > the result of a sync block? Assuming I don't want to factor out a method > object. > > > ex: > > result_p = Pointer.new(:id) > some_queue.sync do > result_p.assign(value_protected_by_queue) > end > result = result_p[0] > > it's not very ruby-ish...
There's no restriction on not using ivars in block. Indeed, even locals are in scope in a block (and with a #sync dispatched block such as the one you provided, there aren't even any threading issues): result = nil Dispatch::Queue.concurrent.sync do result = true end p result #=> true
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel