Class: SharedArray
@include <SharedArray>
The SharedArray class provides an array implementation that shares its state across multiple instances. This class is useful for scenarios in which we’re forking processes and need a shared array between them.
Reads and writes are atomic and concurrency-safe.
The array can be encrypted for security.
Internally, it uses the file system to store the array state.
Methods
@SharedArray.setEncrypted
Scope: public
Sets whether the array should be encrypted. Encrypting the array can mitigate unauthorized reads by other processes. This cannot be changed after the array has been used.
Usage: @SharedArray.setEncrypted $value
Parameters
value
- Type:
primitive
- ‘1’ or ‘true’ enables encryption, any other value disables it.
- Type:
@SharedArray.size
Scope: public
Echoes the number of elements in the shared array.
Usage: @SharedArray.size
@SharedArray.push
Scope: public
Adds a value to the end of the shared array.
Usage: @SharedArray.push $value
Parameters
value
- Type:
primitive
- The value to add to the shared array.
- Type:
@SharedArray.pop
Scope: public
Removes and echoes the last element of the shared array.
Usage: @SharedArray.pop
@SharedArray.insert
Scope: public
Inserts a value at a specific index in the shared array.
Usage: @SharedArray.insert $index $value
Parameters
index
- Type:
primitive
- The index at which to insert the value.
- Type:
value
- Type:
primitive
- The value to insert into the shared array.
- Type:
@SharedArray.remove
Scope: public
Removes the value at a specific index from the shared array.
Usage: @SharedArray.remove $index
Parameters
index
- Type:
primitive
- The index of the value to remove.
- Type:
@SharedArray.at
Scope: public
Gets the value at a specific index in the shared array.
Usage: @SharedArray.at $index
Parameters
index
- Type:
primitive
- The index of the value to retrieve.
- Type:
@SharedArray.front
Scope: public
Echoes the first element of the shared array.
Usage: @SharedArray.front
@SharedArray.back
Scope: public
Echoes the last element of the shared array.
Usage: @SharedArray.back
@SharedArray.all
Scope: public
Echoes all elements of the shared array.
Usage: @SharedArray.all
@SharedArray.empty
Scope: public
Echoes “true” if the shared array is empty, “false” otherwise.
Usage: @SharedArray.empty
@SharedArray.slice
Scope: public
Returns a slice of the shared array from start to end indices.
Usage: @SharedArray.slice $start $end
Parameters
start
- Type:
primitive
- The starting index of the slice (inclusive).
- Type:
end
- Type:
primitive
- The ending index of the slice (inclusive).
- Type:
@SharedArray.clear
Scope: public
Removes all elements from the shared array.
Usage: @SharedArray.clear