lib/daybreak/writer.rb in daybreak-0.1.1 vs lib/daybreak/writer.rb in daybreak-0.1.2

- old
+ new

@@ -3,13 +3,11 @@ # They have a Worker instance that writes in a select loop. class Writer # Open up the file, ready it for binary and nonblocking writing. def initialize(file) @file = file - open! - @worker = Worker.new(@fd) end # Send a record to the workers queue. def write(record) @@ -63,24 +61,24 @@ at_exit { finish! } end # Queue up a write to be committed later. def enqueue(record) - @queue << record.representation + @queue << record end # Loop and block if we don't have work to do or if # the file isn't ready for another write just yet. def work - buf = "" + buf = '' loop do - str = @queue.pop - if str.nil? + record = @queue.pop + unless record @fd.flush break end - buf << str + buf << Record.serialize(record) read, write = IO.select [], [@fd] if write and fd = write.first lock(fd, File::LOCK_EX) { buf = try_write fd, buf } end end @@ -96,10 +94,10 @@ s = fd.write(buf) end if s < buf.length buf = buf[s..-1] # didn't finish else - buf = "" + buf = '' end rescue Errno::EAGAIN buf = buf # try this again end buf