Class: EventedQueue::Recurring

Inherits:
EventedQueue show all
Defined in:
lib/evented-queue/recurring.rb

Overview

Recurring evented queue implementation.

Instance Attribute Summary collapse

Attributes inherited from EventedQueue

#callbacks, #stack

Instance Method Summary collapse

Methods inherited from EventedQueue

#clear, #empty?, #length, #push

Methods inherited from AbstractEventedQueue

#clear, #empty?, #length, #push

Constructor Details

#initialize(stack = UnifiedQueues::Single::new(Array), &scheduler) ⇒ Recurring

Constructor.

Parameters:

  • &scheduler (Proc)

    which indicates how to schedule recurring



25
26
27
28
# File 'lib/evented-queue/recurring.rb', line 25

def initialize(stack = UnifiedQueues::Single::new(Array), &scheduler)
    super(stack)
    @scheduler = scheduler
end

Instance Attribute Details

#schedulerProc

Holds scheduling routine.

Returns:

  • (Proc)


17
18
19
# File 'lib/evented-queue/recurring.rb', line 17

def scheduler
  @scheduler
end

Instance Method Details

#pop {|Object| ... } ⇒ Object

Pushes value out of the queue.

Yields:

  • (Object)

    value from the queue

Returns:

  • (Object)

    value from the queue



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/evented-queue/recurring.rb', line 37

def pop(&block)
    if self.empty?
        result = super(&block)
    else
        result = super(&block)
        
        if @scheduler.nil?
            self.pop(&block)
        else
            @scheduler.call(Proc::new { self.pop(&block) })
        end
    end
    
    return result
end