Class: Jekyll::Utils::ThreadEvent
- Inherits:
-
Object
- Object
- Jekyll::Utils::ThreadEvent
- Defined in:
- lib/jekyll/utils/thread_event.rb
Overview
Based on the pattern and code from emptysqua.re/blog/an-event-synchronization-primitive-for-ruby/
Instance Attribute Summary collapse
-
#flag ⇒ Object
readonly
Returns the value of attribute flag.
Instance Method Summary collapse
-
#initialize ⇒ ThreadEvent
constructor
A new instance of ThreadEvent.
- #set ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize ⇒ ThreadEvent
Returns a new instance of ThreadEvent.
10 11 12 13 14 |
# File 'lib/jekyll/utils/thread_event.rb', line 10 def initialize @lock = Mutex.new @cond = ConditionVariable.new @flag = false end |
Instance Attribute Details
#flag ⇒ Object (readonly)
Returns the value of attribute flag.
8 9 10 |
# File 'lib/jekyll/utils/thread_event.rb', line 8 def flag @flag end |
Instance Method Details
#set ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/jekyll/utils/thread_event.rb', line 16 def set @lock.synchronize do yield if block_given? @flag = true @cond.broadcast end end |
#wait ⇒ Object
24 25 26 27 28 |
# File 'lib/jekyll/utils/thread_event.rb', line 24 def wait @lock.synchronize do @cond.wait(@lock) unless @flag end end |