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.
25 26 27 28 29 |
# File 'lib/application_insights/channel/event.rb', line 25 def initialize @mutex = Mutex.new @condition_variable = ConditionVariable.new @signal = false end |
Instance Attribute Details
#signal ⇒ Boolean (readonly)
35 36 37 |
# File 'lib/application_insights/channel/event.rb', line 35 def signal @signal end |
Instance Method Details
#clear ⇒ Object
Sets the internal flag to false.
47 48 49 50 51 |
# File 'lib/application_insights/channel/event.rb', line 47 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.
39 40 41 42 43 44 |
# File 'lib/application_insights/channel/event.rb', line 39 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.
59 60 61 62 63 64 65 |
# File 'lib/application_insights/channel/event.rb', line 59 def wait(timeout=nil) @mutex.synchronize do @condition_variable.wait(@mutex, timeout) unless @signal end @signal end |