Class: SharedQueue

@include <SharedQueue>

Queue which can be shared between multiple concurrent processes

Reads and writes are atomic and concurrency-safe. The queue can be encrypted for security. Internally, it uses the file system to store the queue state.

Methods

@SharedQueue.size

Scope: public

Echo the number of elements in the queue.

Outputs: The number of elements in the queue.

Usage: @SharedQueue.size

@SharedQueue.enqueue

Scope: public

Add a value to the back of the queue.

Usage: @SharedQueue.enqueue $value

Parameters

  • value
    • Type: Primitive
    • The value to add to the queue.

@SharedQueue.dequeue

Scope: public

Remove the front element from the queue and echo it.

Returns: 1 if the queue is empty, 0 otherwise.

Outputs: The value at the front of the queue.

Usage: @SharedQueue.dequeue

@SharedQueue.front

Scope: public

Echo the front element of the queue without removing it.

Returns: 1 if the queue is empty, 0 otherwise.

Outputs: The value at the front of the queue.

Usage: @SharedQueue.front

@SharedQueue.back

Scope: public

Echo the back element of the queue without removing it.

Returns: 1 if the queue is empty, 0 otherwise.

Outputs: The value at the back of the queue.

Usage: @SharedQueue.back

@SharedQueue.clear

Scope: public

Clear all elements from the queue.

Usage: @SharedQueue.clear

@SharedQueue.empty

Scope: public

Silently check whether the queue is empty.

Returns: 0 if the queue is empty, 1 otherwise.

Outputs: nothing

Usage: @SharedQueue.empty

@SharedQueue.setEncrypted

Scope: public

Set whether the object should be encrypted.

Encrypting the object can mitigate unauthorized reads by other processes. This flag cannot be changed after the object has been used.

Returns: 1 if the object has already been used or ‘openssl’ is unavailable, 0 otherwise.

Usage: @SharedQueue.setEncrypted $value

Parameters

  • value
    • Type: Primitive
    • ‘1’ or ‘true’ enables encryption, any other value disables it.

@SharedQueue.lock

Scope: public

Lock the shared object for exclusive access

Once locked, only the process which locked it can access the object until it is unlocked. Attempts by other processes to access the object will block until it is unlocked.

Returns: 1 if the lock could not be acquired, 0 otherwise.

Usage: @SharedQueue.lock

@SharedQueue.unlock

Scope: public

Unlock the shared object, allowing other processes to access it.

Returns: 1 if the object was not locked by this process, 0 otherwise.

Usage: @SharedQueue.unlock