Class: Mutant::Variable::IVar Private

Inherits:
Mutant::Variable show all
Defined in:
lib/mutant/variable.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Shared variable that can be written at most once

ignore :reek:InstanceVariableAssumption

Defined Under Namespace

Classes: Error

Constant Summary

Constants inherited from Mutant::Variable

EMPTY, TIMEOUT

Instance Method Summary collapse

Methods inherited from Mutant::Variable

#initialize, #read, #take, #take_timeout, #try_put, #with

Constructor Details

This class inherits a constructor from Mutant::Variable

Instance Method Details

#populate_withObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Populate and return value, use block to compute value if empty

The block is guaranteed to be executed at max once.

Subsequent reads are guaranteed to return the block value.

Returns:

  • (Object)


249
250
251
252
253
254
255
256
257
# File 'lib/mutant/variable.rb', line 249

def populate_with
  return @value if full?

  synchronize do
    perform_put(yield) if empty?
  end

  @value
end

#put(value) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Put value, raises if already full

Parameters:

  • value (Object)

Returns:

  • (self)

Raises:

  • Error if already full



233
234
235
236
237
238
239
240
# File 'lib/mutant/variable.rb', line 233

def put(value)
  synchronize do
    fail Error, 'is immutable' if full?
    perform_put(value)
  end

  self
end