class Zold::Stress::Air

Flying payments.

Public Class Methods

new() click to toggle source
# File lib/zold/stress/air.rb, line 30
def initialize
  @mutex = Mutex.new
  @all = []
end

Public Instance Methods

add(pmt) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/zold/stress/air.rb, line 35
def fetch(any = false)
  @all.select { |p| any || p[:arrived].nil? }
end
pulled(id) click to toggle source
# 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