Class: TestScript
- Inherits:
-
Object
- Object
- TestScript
- Defined in:
- lib/gearman/testlib.rb
Instance Method Summary collapse
- #exec(&f) ⇒ Object
-
#initialize ⇒ TestScript
constructor
A new instance of TestScript.
- #loop_forever ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize ⇒ TestScript
Returns a new instance of TestScript.
62 63 64 65 66 |
# File 'lib/gearman/testlib.rb', line 62 def initialize @mutex = Mutex.new @cv = ConditionVariable.new @blocks = [] end |
Instance Method Details
#exec(&f) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/gearman/testlib.rb', line 83 def exec(&f) @mutex.synchronize do @blocks << f @cv.signal end end |
#loop_forever ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gearman/testlib.rb', line 68 def loop_forever loop do f = nil @mutex.synchronize do @cv.wait(@mutex) if @blocks.empty? f = @blocks[0] if not @blocks.empty? end f.call if f @mutex.synchronize do @blocks.shift @cv.signal if @blocks.empty? end end end |
#wait ⇒ Object
90 91 92 93 94 |
# File 'lib/gearman/testlib.rb', line 90 def wait @mutex.synchronize do @cv.wait(@mutex) if not @blocks.empty? end end |