Class: UnifiedQueues::Single::Driver::ArrayDriver

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

Overview

Array queue driver. Uses standard library Array class for 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.



67
68
69
# File 'lib/unified-queues/single/driver/array.rb', line 67

def clear!
    @native.clear
end

#empty?Boolean

Indicates queue is empty.

Parameters:

  • +true+ (Boolean)

    if it’s, false otherwise

Returns:

  • (Boolean)


59
60
61
# File 'lib/unified-queues/single/driver/array.rb', line 59

def empty?
    @native.empty?
end

#lengthInteger

Returns length of the queue.

Returns:

  • (Integer)


76
77
78
# File 'lib/unified-queues/single/driver/array.rb', line 76

def length
    @native.length
end

#pop(blocking = false) ⇒ Object

Pops value out of the queue. Blocking isn’ŧ supported.

Parameters:

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

    true or timeout if it should block, false otherwise

Returns:

  • (Object)

    out-queued value



50
51
52
# File 'lib/unified-queues/single/driver/array.rb', line 50

def pop(blocking = false)
    @native.shift
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



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

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

#type:linear

Returs type of the queue.

Returns:

  • (:linear)


85
86
87
# File 'lib/unified-queues/single/driver/array.rb', line 85

def type
    :linear
end