Class: Zold::Stress::Air
- Inherits:
-
Object
- Object
- Zold::Stress::Air
- Defined in:
- lib/zold/stress/air.rb
Overview
Flying payments.
Instance Method Summary collapse
- #add(pmt) ⇒ Object
- #arrived(pmt) ⇒ Object
- #fetch(any = false) ⇒ Object
-
#initialize ⇒ Air
constructor
A new instance of Air.
- #pulled(id) ⇒ Object
Constructor Details
#initialize ⇒ Air
Returns a new instance of Air.
30 31 32 33 |
# File 'lib/zold/stress/air.rb', line 30 def initialize @mutex = Mutex.new @all = [] end |
Instance Method Details
#add(pmt) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/zold/stress/air.rb', line 39 def add(pmt) @mutex.synchronize do raise "Payment already exists (#{@all.size} total): #{pmt}" if @all.find { |p| p[:details] == pmt[:details] } @all << pmt.merge(pushed: Time.now) end end |
#arrived(pmt) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/zold/stress/air.rb', line 52 def arrived(pmt) @mutex.synchronize do found = @all.find { |p| p[:details] == pmt[:details] } raise "Payment doesn't exist (#{@all.size} total): #{pmt}" if found.nil? found[:arrived] = Time.now end end |
#fetch(any = false) ⇒ Object
35 36 37 |
# File 'lib/zold/stress/air.rb', line 35 def fetch(any = false) @all.select { |p| any || p[:arrived].nil? } end |
#pulled(id) ⇒ Object
46 47 48 49 50 |
# File 'lib/zold/stress/air.rb', line 46 def pulled(id) @mutex.synchronize do @all.select { |a| a[:target] == id }.each { |a| a[:pulled] = Time.now } end end |