Class: RWGet::Queue
- Inherits:
-
Object
- Object
- RWGet::Queue
- Defined in:
- lib/rwget/queue.rb
Instance Method Summary collapse
- #close ⇒ Object
- #get(retrying = false) ⇒ Object
-
#initialize(options = {}) ⇒ Queue
constructor
A new instance of Queue.
- #put(key, depth) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Queue
Returns a new instance of Queue.
3 4 5 6 7 |
# File 'lib/rwget/queue.rb', line 3 def initialize( = {}) @writer = Tempfile.new("rwget-queue") @reader = File.open(@writer.path, "r") @dirty = false end |
Instance Method Details
#close ⇒ Object
28 29 30 31 |
# File 'lib/rwget/queue.rb', line 28 def close @writer.close @reader.close end |
#get(retrying = false) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rwget/queue.rb', line 14 def get( = false) sleep 0.1 if if @dirty @writer.flush @dirty = false end line = @reader.gets unless line return ? nil : get(:retry) end key, depth = line.split("\t") return [key, depth.to_i] end |
#put(key, depth) ⇒ Object
9 10 11 12 |
# File 'lib/rwget/queue.rb', line 9 def put(key, depth) @writer.puts "#{key}\t#{depth}" @dirty = true end |