class FileSyncedQueue

Public Class Methods

new(path,max_limit=1000) click to toggle source
# File lib/file_synced_queue.rb, line 7
def initialize(path,max_limit=1000)
  @save_path = path
  unless File.exists? path and File.file? path then
    raise "ファイルじゃない。"  if File.exists? path and not File.file? path
  end
  @m = Mutex.new
  at_exit{
    self.save
  }
  @q =self.load                  if     File.exists? path
  @q = SizedQueue.new(max_limit) unless File.exists? path
  self.save 
end

Public Instance Methods

<<(val)
Alias for: push
deq()
Alias for: pop
enq(val)
Alias for: push
load() click to toggle source
# File lib/file_synced_queue.rb, line 20
def load
  @q = Marshal.load open(@save_path).read
end
pop() click to toggle source
# File lib/file_synced_queue.rb, line 35
def pop()
  val = @q.pop
  @m.synchronize{
    self.save    
  }
  val
end
Also aliased as: shift, deq
push(val) click to toggle source
# File lib/file_synced_queue.rb, line 29
def push(val)
  @q.push val
  @m.synchronize{
    self.save    
  }
end
Also aliased as: enq, <<
save() click to toggle source
# File lib/file_synced_queue.rb, line 23
def save
  f = open(@save_path,"w")
  Marshal.dump(@q,f)
  f.flush
  f.close
end
shift()
Alias for: pop