Created
February 9, 2010 01:37
-
-
Save drernie/298817 to your computer and use it in GitHub Desktop.
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
require 'dispatch' | |
T=1 | |
T0 = Time.now | |
def now | |
(Time.now - T0) | |
end | |
p "Call Dispatch.sync with delay #{T} @ #{now}" | |
Dispatch.sync {sleep T; p "Waited for me"} | |
p "Finished calling sync @ #{now}" | |
puts | |
p "Call Dispatch.async with delay #{T} @ #{now}" | |
Dispatch.async {sleep T; p "Didn't wait for me"} | |
p "Finished calling async @ #{now}" | |
sleep 2*T | |
puts | |
p "Calling Dispatch.fork with delay #{T} @ #{now}" | |
g = Dispatch.fork {sleep T; p "Tell me when done"} | |
p "Calling Dispatch.group with delay #{T} @ #{now}" | |
Dispatch.group(g) {sleep T; p "Me too"} | |
p "Calling Group.join to wait for both..." | |
g.wait | |
p "All done @ #{now}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment