Created
January 13, 2011 21:55
-
-
Save hopsoft/778696 to your computer and use it in GitHub Desktop.
Testing the GCD system in MacRuby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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