Method: Garcon::LazyReference#initialize

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

#initialize(default = nil) { ... } ⇒ LazyReference

Creates a new unfulfilled object.

Parameters:

  • default (Object) (defaults to: nil)

    The default value for the object when the block raises an exception.

Yields:

  • the delayed operation to perform

Raises:

  • (ArgumentError)

    if no block is given



41
42
43
44
45
46
47
48
# File 'lib/garcon/task/lazy_reference.rb', line 41

def initialize(default = nil, &block)
  raise ArgumentError, 'no block given' unless block_given?
  @default   = default
  @task      = block
  @mutex     = Mutex.new
  @value     = nil
  @fulfilled = false
end