Method: Garcon::LazyReference#value

Defined in:
lib/garcon/task/lazy_reference.rb

#valueObject

The calculated value of the object or the default value if one was given at construction. This first time this method is called it will block indefinitely while the block is processed. Subsequent calls will not block.

Returns:

  • (Object)

    the calculated value



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/garcon/task/lazy_reference.rb', line 57

def value
  return @value if @fulfilled

  @mutex.synchronize do
    unless @fulfilled
      begin
        @value = @task.call
      rescue
        @value = @default
      ensure
        @fulfilled = true
      end
    end
    return @value
  end
end