Created
March 8, 2013 01:02
-
-
Save pote/5113400 to your computer and use it in GitHub Desktop.
Promises are Futures.
This file contains 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 'celluloid' | |
class Politician | |
include Celluloid | |
def lower_taxes | |
# Try really hard to do this | |
result_of_complicated_code = [true, false].sample | |
yield result_of_complicated_code | |
end | |
end | |
some_dude = Politician.new | |
promise = some_dude.future.lower_taxes do |result| | |
result ? 'this was successful' : 'this was unsuccessful' | |
end | |
puts promise.value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment