class Variable::MVar

Shared variable that can be written multiple times

ignore :reek:InstanceVariableAssumption

Public Class Methods

new(condition_variable:, mutex:, value: EMPTY) click to toggle source

Initialize object

@param [Object] value

the initial value

@return [undefined]

Calls superclass method
# File lib/variable.rb, line 281
def initialize(condition_variable:, mutex:, value: EMPTY)
  super
  @empty = condition_variable.new
end

Public Instance Methods

modify() { |value| ... } click to toggle source

Modify value, blocks if empty

@return [Object]

# File lib/variable.rb, line 303
def modify
  synchronize do
    wait_full
    perform_put(yield(@value))
  end
end
put(value) click to toggle source

Put value, block on full

@param [Object] value

@return [self]

# File lib/variable.rb, line 291
def put(value)
  synchronize do
    wait(@empty, &method(:empty?))
    perform_put(value)
  end

  self
end

Private Instance Methods

perform_take() click to toggle source

Empty the variable

@return [Object]

# File lib/variable.rb, line 315
def perform_take
  @value.tap do
    @value = EMPTY
    @empty.signal
  end
end