@include <SharedQueue>

The SharedQueue class provides a queue implementation that shares its state across multiple instances. This class is useful for scenarios in which we’re forking processes and need a shared queue between them.

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

Echoes the number of elements in the queue.

Usage: @SharedQueue.size

@SharedQueue.enqueue

Scope: public

Adds 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

Removes the front element from the queue and echoes it.

Usage: @SharedQueue.dequeue

@SharedQueue.front

Scope: public

Echoes the front element of the queue without removing it.

Usage: @SharedQueue.front

@SharedQueue.back

Scope: public

Echoes the back element of the queue without removing it.

Usage: @SharedQueue.back

@SharedQueue.clear

Scope: public

Removes all elements from the queue.

Usage: @SharedQueue.clear

@SharedQueue.empty

Scope: public

Echoes “true” if the queue is empty, “false” otherwise.

Usage: @SharedQueue.empty

@SharedQueue.setEncrypted

Scope: public

Sets whether the object should be encrypted. Encrypting the object can mitigate unauthorized reads by other processes.

This cannot be changed after the object has been used.

Usage: @SharedQueue.setEncrypted $value

Parameters

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

@SharedQueue.lock

Scope: public

Locks 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 access the object while it is locked will block until it is unlocked.

Using this method (as opposed to the internal _lock method) sets the extended_lock flag to 1, indicating that the lock should not be dropped until explicitly unlocked. I.e., subsequent calls to _unlock (internal) will not release the lock until unlock (public) is called.

Usage: @SharedQueue.lock

@SharedQueue.unlock

Scope: public

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

This also resets the extended_lock flag to 0.

Usage: @SharedQueue.unlock