Class: Kameleoon::ClientReadiness

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/client_readiness.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClientReadiness

Returns a new instance of ClientReadiness.



9
10
11
12
13
14
# File 'lib/kameleoon/client_readiness.rb', line 9

def initialize
  @is_initializing = false
  @success = false
  @condition = Concurrent::ReadWriteLock.new
  reset
end

Instance Attribute Details

#is_initializingObject (readonly)

Returns the value of attribute is_initializing.



7
8
9
# File 'lib/kameleoon/client_readiness.rb', line 7

def is_initializing
  @is_initializing
end

#successObject (readonly)

Returns the value of attribute success.



7
8
9
# File 'lib/kameleoon/client_readiness.rb', line 7

def success
  @success
end

Instance Method Details

#resetObject



16
17
18
19
20
21
22
# File 'lib/kameleoon/client_readiness.rb', line 16

def reset
  @success = false
  unless @is_initializing
    @is_initializing = true
    @condition.acquire_write_lock
  end
end

#set(success) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/kameleoon/client_readiness.rb', line 24

def set(success)
  @success = success
  if @is_initializing
    @condition.release_write_lock
    @is_initializing = false
  end
end

#waitObject



32
33
34
35
36
37
38
# File 'lib/kameleoon/client_readiness.rb', line 32

def wait
  if @is_initializing
    @condition.acquire_read_lock
    @condition.release_read_lock
  end
  @success
end