Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Created January 13, 2011 21:55
Show Gist options
  • Save hopsoft/778696 to your computer and use it in GitHub Desktop.
Save hopsoft/778696 to your computer and use it in GitHub Desktop.
Testing the GCD system in MacRuby
def async_example(arg, delay=1.0)
Dispatch::Queue.new('org.macruby.examples.gcd').async do
start = Time.now
sleep delay
puts "finished async_work for: #{arg} in #{(Time.now - start).round} secs"
end
end
async_example(:first, 5.0)
async_example(:second, 4.0)
async_example(:third, 3.0)
async_example(:fourth, 2.0)
async_example(:fifth, 1.0)
async_example(:sixth, 0.0)
async_example(:seventh, 0.0)
async_example(:eighth, 0.0)
async_example(:ninth, 0.0)
async_example(:tenth, 0.0)
# produces
# finished async_work for: sixth in 0 secs
# finished async_work for: seventh in 0 secs
# finished async_work for: eighth in 0 secs
# finished async_work for: ninth in 0 secs
# finished async_work for: tenth in 0 secs
# finished async_work for: fourth in 2 secs
# finished async_work for: third in 3 secs
# finished async_work for: second in 4 secs
# finished async_work for: first in 5 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment