Created
November 1, 2010 23:09
-
-
Save bakkdoor/659033 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
def async do_something_slow_with_each: array { | |
results = [] | |
array each: |x| { | |
# await basically tells the compiler that we'll switch context and | |
# resume when "x do_something_slow" is finished | |
# note that the method seems synchronously since we're just | |
# defining a loop etc. | |
# the compiler knows how to transform all of this since it knows | |
# it's a "async" method (see method def at top) | |
result = await x do_something_slow | |
results << result | |
} | |
return results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment