Class: ThreadSafeLru::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/threadsafe-lru/ThreadSafeLruCache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Node

Returns a new instance of Node.



64
65
66
67
68
69
# File 'lib/threadsafe-lru/ThreadSafeLruCache.rb', line 64

def initialize key
  @key=key
  @produced=false
  @value=nil
  @lock=Mutex.new
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



71
72
73
# File 'lib/threadsafe-lru/ThreadSafeLruCache.rb', line 71

def key
  @key
end

Instance Method Details

#get_value(block) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/threadsafe-lru/ThreadSafeLruCache.rb', line 73

def get_value block
  @lock.synchronize do
    unless (@produced)
      @value=block.call @key
      @produced=true
    end
    @value
  end
end