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
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
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
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