Skip to content

Instantly share code, notes, and snippets.

@jasiek
Created March 11, 2012 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasiek/2017291 to your computer and use it in GitHub Desktop.
Save jasiek/2017291 to your computer and use it in GitHub Desktop.
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