Class: Shoryuken::Helpers::AtomicBoolean

Inherits:
AtomicCounter show all
Defined in:
lib/shoryuken/helpers/atomic_boolean.rb

Overview

A thread-safe boolean implementation using AtomicCounter as base. Drop-in replacement for Concurrent::AtomicBoolean without external dependencies. Uses 1 for true and 0 for false internally.

Instance Method Summary collapse

Methods inherited from AtomicCounter

#decrement, #increment

Constructor Details

#initialize(initial_value = false) ⇒ AtomicBoolean

Returns a new instance of AtomicBoolean.



12
13
14
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 12

def initialize(initial_value = false)
  super(initial_value ? 1 : 0)
end

Instance Method Details

#false?Boolean

Check if the value is false

Returns:



39
40
41
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 39

def false?
  @mutex.synchronize { @value == 0 }
end

#make_falseObject

Set the value to false



28
29
30
31
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 28

def make_false
  @mutex.synchronize { @value = 0 }
  false
end

#make_trueObject

Set the value to true



22
23
24
25
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 22

def make_true
  @mutex.synchronize { @value = 1 }
  true
end

#true?Boolean

Check if the value is true

Returns:



34
35
36
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 34

def true?
  @mutex.synchronize { @value != 0 }
end

#valueObject

Get the current value as boolean



17
18
19
# File 'lib/shoryuken/helpers/atomic_boolean.rb', line 17

def value
  super != 0
end