Module: Streamit::AsyncQueue

Included in:
Streamit
Defined in:
lib/streamit/async_queue.rb

Instance Method Summary collapse

Instance Method Details

#enqueue(args) ⇒ Object



4
5
6
# File 'lib/streamit/async_queue.rb', line 4

def enqueue(args)
  queue << args
end

#finish!Object



8
9
10
11
12
13
# File 'lib/streamit/async_queue.rb', line 8

def finish!
  queue << nil
  thread.join
  @thread = nil
  thread
end

#process(args) ⇒ Object

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/streamit/async_queue.rb', line 27

def process(args)
  raise NotImplementedError
end

#queueObject



15
16
17
# File 'lib/streamit/async_queue.rb', line 15

def queue
  @queue ||= Queue.new
end

#threadObject



19
20
21
22
23
24
25
# File 'lib/streamit/async_queue.rb', line 19

def thread
  @thread ||= Thread.new do
    while args = queue.pop
      process(args)
    end
  end
end