Class: UnifiedQueues::Single::Driver::QueueDriver

Inherits:
UnifiedQueues::Single::Driver show all
Defined in:
lib/unified-queues/single/driver/queue.rb

Overview

Queue queue driver. Uses standard library Queue class for thread synchronized queueing. Priority isn’t supported.

Instance Attribute Summary

Attributes inherited from UnifiedQueues::Single::Driver

#native

Instance Method Summary collapse

Methods inherited from UnifiedQueues::Single::Driver

#evented?, #initialize, #linear?

Constructor Details

This class inherits a constructor from UnifiedQueues::Single::Driver

Instance Method Details

#clear!Object

Clears the queue.



78
79
80
# File 'lib/unified-queues/single/driver/queue.rb', line 78

def clear!
    @native.clear
end

#empty?Boolean

Indicates queue is empty.

Parameters:

  • +true+ (Boolean)

    if it’s, false otherwise

Returns:

  • (Boolean)


70
71
72
# File 'lib/unified-queues/single/driver/queue.rb', line 70

def empty?
    @native.empty?
end

#lengthInteger

Returns length of the queue.

Returns:

  • (Integer)


87
88
89
# File 'lib/unified-queues/single/driver/queue.rb', line 87

def length
    @native.length
end

#pop(blocking = false) ⇒ Object

Pops value out of the queue.

Parameters:

  • blocking (Boolean|Integer) (defaults to: false)

    true or timeout if it should block, false otherwise

  • queue (Object)

    value



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/unified-queues/single/driver/queue.rb', line 51

def pop(blocking = false)
    if blocking.boolean?
        timeout = !blocking
    else
        timeout = blocking                        
    end

    begin
        @native.pop(blocking)
    rescue ThreadError
        nil
    end
end

#push(value, key = value) ⇒ Object

Pushes the value into the queue. Priority isn’t supported.

Parameters:

  • value (Object)

    value for push

  • key (Object) (defaults to: value)

    key for priority queues



40
41
42
# File 'lib/unified-queues/single/driver/queue.rb', line 40

def push(value, key = value)
    @native.push(value)
end

#type:linear

Returs type of the queue.

Returns:

  • (:linear)


96
97
98
# File 'lib/unified-queues/single/driver/queue.rb', line 96

def type
    :linear
end