Sha256: b16af06af60195d1781e1dc0187e0270dc65555af11eb571b627b2f52def354e
Contents?: true
Size: 793 Bytes
Versions: 12
Compression:
Stored size: 793 Bytes
Contents
require "thread" class FutureResource def initialize @resource_lock = Monitor.new @resource_value_blocker = @resource_lock.new_cond end def set_yet? @resource_lock.synchronize { defined? @resource } end def resource @resource_lock.synchronize do @resource_value_blocker.wait unless defined? @resource @resource end end def resource=(resource) @resource_lock.synchronize do raise ResourceAlreadySetException if defined? @resource @resource = resource @resource_value_blocker.broadcast @resource_value_blocker = nil # Don't really need it anymore. end end class ResourceAlreadySetException < Exception def initialize super "Cannot set this resource twice!" end end end
Version data entries
12 entries across 12 versions & 6 rubygems