Queues

FIFO

class fifo(max_size)

Fifo class

Creates a new First-In-First-Out Queue with at most max_size elements

Arguments:
  • max_size (int) – Maximum queue size
fifo.flush()

Deletes the entire queue removing all elements.

fifo.peek()

Returns one element of the queue without removing the element.

Returns:any – The element or null on failure
fifo.pull()

Extracts one element of the queue. The element will be removed from the queue.

Returns:any – The element or null on failure.
fifo.push(value)

Adds a new element to the queue. If max_size is reached no element will be added.

Arguments:
  • value (any) – The value to add
Returns:

boolean – true if current queue size isn’t greater than max_size. Otherwise false.

Asynchronous Fifo

New in version 0.2.0.

class AsyncFifo(max_size)

Asynchronous fifo implementation

Arguments:
  • max_size (int) – Maximum queue size
AsyncFifo.flush()

Flushes the queue and emits an flush event

AsyncFifo.on(ev, callback)

Adds a new event listener

Arguments:
  • ev (string) – Event name
  • callback (callback) – which should be attached to the queue.
AsyncFifo.pull()

Pulls a value synchronously, if the queue is empty, an empty event is emitted

AsyncFifo.push(value)

Pushes a new value to the queue and emits an data event or an full event if the maximum queue size is reached.

Arguments:
  • value (any) – Value which should be enqueued.

Fifo Events

The queue emits the following events:

data
The data event is emitted if a new item is available to be processed If multiple listeners are attached to this event, only one listener can pull the same item. The callback gets a reference to the fifo queue. You can call pull on the reference to retrieve the last enqueued item.
full
This emit is emitted if the queue’s maximum size is reached.
empty
This event is emitted if pull is called and there are no items available.
flush
This event is emitted if someone flushes the queue.

LIFO (Stack)

class lifo(max_size)

Represents a LIFO - Queue (Stack)

Creates a Last-In-First-Out Queue with at most max_size elements.

Arguments:
  • max_size (int) – Maximum queue size
lifo.flush()

Flushes the entire stack

lifo.peek()

Returns the last element, but does not delete it from the stack.

Returns:any – the value.
lifo.pop()

Pops one element from the stack

Returns:any – the value.
lifo.push(value)

Pushes on element ot the stack.

Arguments:
  • value (any) – The value you want to push to the stack.
Returns:

boolean – true if the current stack size doesn’t exceed the maximum stack size.

lifo.size

Returns the current stack size

class ArrayStack(max_size)

Provides a fast stack as an Array

Creates a new stack with at most max_size elements

Arguments:
  • max_size (int) – maximum stack size or Infinity for unlimited stacks.
ArrayStack.flush()

Deletes the entire stack

ArrayStack.peek()

Returns the top most element of the stack, but does not delete it.

Returns:any – any element
ArrayStack.pop()

pops one element off the stack.

Returns:any – any element
ArrayStack.push(val)

Pushes a new value to the stack

Arguments:
  • val (any) – Value which should be pushed to the stack.