class ParallelTests::Pids
def add(pid)
def add(pid) pids << pid.to_i save end
def all
def all read pids end
def clear
def clear @pids = [] save end
def count
def count read pids.count end
def delete(pid)
def delete(pid) pids.delete(pid.to_i) save end
def initialize(file_path)
def initialize(file_path) @file_path = file_path @mutex = Mutex.new end
def pids
def pids @pids ||= [] end
def read
def read sync do contents = IO.read(file_path) return if contents.empty? @pids = JSON.parse(contents) end end
def save
def save sync { IO.write(file_path, pids.to_json) } end
def sync
def sync mutex.synchronize { yield } end