Skip to content

Instantly share code, notes, and snippets.

@rthbound
Created August 17, 2015 19:49
Show Gist options
  • Save rthbound/224b795040ae2dcb593a to your computer and use it in GitHub Desktop.
Save rthbound/224b795040ae2dcb593a to your computer and use it in GitHub Desktop.
def lookup(x); { a: 1, b: 2, c: 3 }[x]; end
def promos; { x: :a, y: :b, z: :c }; end
@promo_counts = Concurrent::Promise.fulfill(@promos = promos).then { |val| Concurrent::Promise.zip(*val.map { |x,v| Concurrent::Promise.new { { x => lookup(v) } } }).value }.value
#=> [{:x=>1}, {:y=>2}, {:z=>3}]
@promos
#=> {:x=>:a, :y=>:b, :z=>:c}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment