Skip to main content

SharedBag<T> (class)

Transaction-guided data collection focused on being safe for concurrent operations.

Status: unstable

Constructor Parameters

NameTypeDescription
...contentT[]Items to be added by default inside the collection

Example usage

const sharedBag = new SharedBag<number>(1, 2, 3, 4);

Extra behaviors

ConditionConsequenceWorkaround
Instability noteThe current method set of SharedBag<T> doesn't meet all the requirements to be an useful collection since the data can't be removed or retrieved from itSee issue #55

Instance Methods

SharedBag.beginTransaction()

Begins a transaction and returns an specific uuid.

Status: stable
Returns: string

Parameters

Example usage

const sharedBag = new SharedBag<number>(1, 2, 3, 4);
const transactionId = sharedBag.beginTransaction();

Extra behaviors

ConditionConsequenceWorkaround
Calling the method when there is an active transation runningAn Error will be thrown because SharedBag can support only one transaction per timeClose the last active transaction before calling beginTransaction

SharedBag.closeTransaction()

Ends a transaction.

Status: stable
Returns: void

Parameters

Example usage

const sharedBag = new SharedBag<number>(1, 2, 3, 4);
const transactionId = sharedBag.beginTransaction();
sharedBag.closeTransaction();

Extra behaviors

ConditionConsequenceWorkaround
Calling the method when there is no active transation runningAn Error will be thrown because there is no transaction to be closed in that contextStart a new transaction using beginTransaction

SharedBag.addFirst(value)

Put a new value in the beginning of the collection and returns the new collection length.

Status: stable
Returns: number

Parameters

NameTypeDescription
valueTThe value to be added in the beginning of the collection

Example usage

const sharedBag = new SharedBag<number>(1, 2, 3, 4);
const transactionId = sharedBag.beginTransaction();
sharedBag.addFirst(0);
sharedBag.closeTransaction();

Extra behaviors

ConditionConsequenceWorkaround
Calling the method when there is no active transation runningAn Error will be thrown because there is no transaction to execute the method in that contextStart a new transaction using beginTransaction

SharedBag.addLast(value)

Put a new value in the end of the collection and returns the new collection length.

Status: stable
Returns: number

Parameters

NameTypeDescription
valueTThe value to be added in the beginning of the collection

Example usage

const sharedBag = new SharedBag<number>(1, 2, 3, 4);
const transactionId = sharedBag.beginTransaction();
sharedBag.addLast(5);
sharedBag.closeTransaction();

Extra behaviors

ConditionConsequenceWorkaround
Calling the method when there is no active transation runningAn Error will be thrown because there is no transaction to execute the method in that contextStart a new transaction using beginTransaction