IConsensusOrderedCollection Interface
Consensus Ordered Collection interface
An consensus ordered collection is a distributed data structure, which holds a collection of JSON-able or handles, and has a deterministic add/remove order.
Signature
export interface IConsensusOrderedCollection<T = any> extends ISharedObject<IConsensusOrderedCollectionEvents<T>>
Extends: ISharedObject<IConsensusOrderedCollectionEvents
Type Parameters
| Parameter | Default | Description |
|---|---|---|
| T | any |
Remarks
The order the server receive the add/remove operation determines the order those operation are applied to the collection. Different clients issuing add or acquire operations at the same time will be sequenced. The order dictates which add is done first, thus determining the order in which it appears in the collection. It also determines which client will get the first removed item, etc. All operations are asynchronous. A function waitAndAcquire is provided to wait for and remove an entry in the collection.
As a client acquires an item, it processes it and then returns a value (via callback) indicating whether it has completed processing the item, or whether the item should be released back to the collection for another client to process.
All objects added to the collection will be cloned (via JSON). They will not be references to the original input object. Thus changed to the input object will not reflect the object in the collection.
Methods
| Method | Return Type | Description |
|---|---|---|
| acquire(callback) | Promise<boolean> | Retrieves a value from the collection. |
| add(value) | Promise<void> | Adds a value to the collection |
| waitAndAcquire(callback) | Promise<void> | Wait for a value to be available and remove it from the consensus collection Calls callback with retrieved value. |
Method Details
acquire
Retrieves a value from the collection.
Signature
acquire(callback: ConsensusCallback<T>): Promise<boolean>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| callback | ConsensusCallback<T> |
Returns
Returns true (and calls callback with acquired value) if collection was not empty. Otherwise returns false.
Return type: Promise<boolean>
add
Adds a value to the collection
Signature
add(value: T): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| value | T |
Returns
Return type: Promise<void>
waitAndAcquire
Wait for a value to be available and remove it from the consensus collection Calls callback with retrieved value.
Signature
waitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| callback | ConsensusCallback<T> |
Returns
Return type: Promise<void>