Skip to content

Instantly share code, notes, and snippets.

@bakkdoor
Created November 1, 2010 23:09
Show Gist options
  • Save bakkdoor/659033 to your computer and use it in GitHub Desktop.
Save bakkdoor/659033 to your computer and use it in GitHub Desktop.
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