Class: Mutant::Variable::MVar 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 multiple times

ignore :reek:InstanceVariableAssumption

Constant Summary

Constants inherited from Mutant::Variable

EMPTY, TIMEOUT

Instance Method Summary collapse

Methods inherited from Mutant::Variable

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

Constructor Details

#initialize(condition_variable:, mutex:, value: EMPTY) ⇒ undefined

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.

Initialize object

Parameters:

  • value (Object) (defaults to: EMPTY)

    the initial value



280
281
282
283
# File 'lib/mutant/variable.rb', line 280

def initialize(condition_variable:, mutex:, value: EMPTY)
  super
  @empty = condition_variable.new
end

Instance Method Details

#modifyObject

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.

Modify value, blocks if empty

Returns:

  • (Object)


302
303
304
305
306
307
# File 'lib/mutant/variable.rb', line 302

def modify
  synchronize do
    wait_full
    perform_put(yield(@value))
  end
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, block on full

Parameters:

  • value (Object)

Returns:

  • (self)


290
291
292
293
294
295
296
297
# File 'lib/mutant/variable.rb', line 290

def put(value)
  synchronize do
    wait(@empty, &method(:empty?))
    perform_put(value)
  end

  self
end