SharedArray
Class: SharedArray
@include <SharedArray>
Array that can be shared between multiple concurrent processes
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.size
Scope: public
the number of elements in the shared array.
Outputs: The number of elements in the shared array.
Usage: @SharedArray.size
@SharedArray.push
Scope: public
Add 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
Remove and echo the last element of the shared array.
Returns: 1 if the shared array is empty, 0 otherwise.
Outputs: The last element of the shared array.
Usage: @SharedArray.pop
@SharedArray.insert
Scope: public
Insert a value at a specific index in the shared array.
Returns: 1 if the index is out of bounds, 0 otherwise.
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
Remove the value at a specific index from the shared array.
Returns: 1 if the index is out of bounds, 0 otherwise.
Usage: @SharedArray.remove $index
Parameters
index- Type:
Primitive - The index of the value to remove.
- Type:
@SharedArray.at
Scope: public
Get the value at a specific index in the shared array.
Returns: The value at the specified index, or an error if out of bounds.
Outputs: The value at the specified index.
Usage: @SharedArray.at $index
Parameters
index- Type:
Primitive - The index of the value to retrieve.
- Type:
@SharedArray.front
Scope: public
Echo the first element of the shared array.
Returns: 1 if the shared array is empty, 0 otherwise.
Outputs: The first element of the shared array.
Usage: @SharedArray.front
@SharedArray.back
Scope: public
Echo the last element of the shared array.
Returns: 1 if the shared array is empty, 0 otherwise.
Outputs: The last element of the shared array.
Usage: @SharedArray.back
@SharedArray.all
Scope: public
Echo all elements of the shared array.
Outputs: All elements of the shared array.
Usage: @SharedArray.all
@SharedArray.empty
Scope: public
Silently check if the shared array is empty.
Returns: 0 if the shared array is empty, 1 otherwise.
Outputs: nothing
Usage: @SharedArray.empty
@SharedArray.slice
Scope: public
Echo a slice of the shared array from start to end indices.
Returns: 1 if the start index is greater than the end index or if the shared array is empty, 0 otherwise.
Outputs: The elements in the specified slice (separated by spaces).
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
Remove all elements from the shared array.
Usage: @SharedArray.clear
@SharedArray.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: @SharedArray.setEncrypted $value
Parameters
value- Type:
Primitive - ‘1’ or ‘true’ enables encryption, any other value disables it.
- Type:
@SharedArray.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: @SharedArray.lock
@SharedArray.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: @SharedArray.unlock