Class: ApplicationInsights::Channel::Event
- Inherits:
-
Object
- Object
- ApplicationInsights::Channel::Event
- Defined in:
- lib/application_insights/channel/event.rb
Overview
Instance Attribute Summary collapse
-
#signal ⇒ Boolean
readonly
The signal value for this object.
Instance Method Summary collapse
-
#clear ⇒ Object
Sets the internal flag to false.
-
#initialize ⇒ Event
constructor
Initializes a new instance of the class.
-
#set ⇒ Object
Sets the internal flag to true.
-
#wait(timeout = nil) ⇒ Boolean
Calling this method will block until the internal flag is set to true.
Constructor Details
#initialize ⇒ Event
Initializes a new instance of the class.
23 24 25 26 27 |
# File 'lib/application_insights/channel/event.rb', line 23 def initialize @mutex = Mutex.new @condition_variable = ConditionVariable.new @signal = false end |
Instance Attribute Details
#signal ⇒ Boolean (readonly)
32 33 34 |
# File 'lib/application_insights/channel/event.rb', line 32 def signal @signal end |
Instance Method Details
#clear ⇒ Object
Sets the internal flag to false.
43 44 45 46 47 |
# File 'lib/application_insights/channel/event.rb', line 43 def clear @mutex.synchronize do @signal = false end end |
#set ⇒ Object
Sets the internal flag to true. Calling this method will also cause all waiting threads to awaken.
35 36 37 38 39 40 |
# File 'lib/application_insights/channel/event.rb', line 35 def set @mutex.synchronize do @signal = true @condition_variable.broadcast end end |
#wait(timeout = nil) ⇒ Boolean
Calling this method will block until the internal flag is set to true. If the flag is set to true before calling this method, we will return immediately. If the timeout parameter is specified, the method will unblock after the specified number of seconds.
54 55 56 57 58 59 60 61 |
# File 'lib/application_insights/channel/event.rb', line 54 def wait(timeout=nil) @mutex.synchronize do if @signal == false @condition_variable.wait @mutex, (timeout == nil) ? nil : timeout end @signal end end |