Created
March 11, 2012 17:32
-
-
Save jasiek/2017291 to your computer and use it in GitHub Desktop.
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
class Deferrable < SimpleDelegator | |
# Public: Create a side thread that wraps whatever you need to have available in the future. | |
def initialize(&blk) | |
super(Thread.new(&blk)) | |
end | |
# Internal: We need the result of the computation of this thread NOW, so block on it and return | |
# the value. | |
def __getobj__ | |
super.value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment