Hi Bernd, On Jun 4, 2010, at 1:28 AM, B. Ohr wrote:
Hi,
yesterday I did my first steps with GCD: parsing a very big CSV-file, processing and filtering it and displaying the result in a table view. Before GCD the UI was blocked for more than a minute, now the user can continue working instantly. Hey that’s really, really great!
:-)
There are some issues I don’t understand:
:-(
1. @job.group.notify(Dispatch::Queue.main) {} # gives an error... @job.group.notify(Dispatch::Queue.concurrent) {} # …..while is working
2. @job.group.notify(Dispatch::Queue.concurrent) {} # the block is called twice or more times
Hmm, you should NOT need to call "group" on the @job for normal usage. Could you just use "@job.join" to get the behavior you want?
3. the proxy object does not work here (I’m not sure, that I am using it correctly)
Yeah, the "+=" thing actually replaces the -variable- instead of mutating the object, so it won't do what you want. Look at the README.rdoc for more details: http://github.com/masterkain/macruby/tree/master/lib/dispatch/ Sorry about the formatting... -- Ernie P.
I made a small Xcode project demo out my project and attached it to this mail. (you can multi-click on the job button)
- Bernd
######
require 'dispatch'
class AppController
attr_accessor :calculations, :running
def initialize self.calculations = [] @prefix = 1 @job = Dispatch::Job.new #the main queue is used here because the UI is bound to the calculations array @calc_queue = Dispatch::Queue.main end
def calc_sync &block @calc_queue.async { block.call } end
def nextPrefix prefix = @prefix @prefix += 1 prefix end
def calc1 # @calc_proxy = Dispatch::Proxy.new(self.calculations,@job.group,@calc_queue) @job.add do prefix = nextPrefix 10.times do |i| dur = rand / 4 + 0.2 sleep(dur) c = Calculation.new("#{prefix}:#{i}",dur) calc_sync { self.calculations += [c] } # proxy does not work here: # @calc_proxy += [c] end #NSLog self.calculations.inspect end # why can the notify block be called twice ore more? # if true if !running self.running = true # notifying on the main queue is crashing here: # @job.group.notify(@calc_queue) { NSLog "notify“; self.running = false } @job.group.notify(Dispatch::Queue.concurrent) { NSLog "notify"; self.running = false } end end
def jobAction sender calc1 end
def clearAction sender self.calculations = [] end
end
<gcd_demo.zip>
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel