IConsensusOrderedCollection Interface

Packages > @fluidframework/ordered-collection > IConsensusOrderedCollection

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<T>>

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

List of methods of this class
Method Description
acquire(callback) Retrieves a value from the collection.
add(value) Adds a value to the collection
waitAndAcquire(callback) Wait for a value to be available and remove it from the consensus collection Calls callback with retrieved value.

Methods

acquire

Retrieves a value from the collection.

Signature:

acquire(callback: ConsensusCallback<T>): Promise<boolean>;

Parameters

List of parameters
Parameter Type Description
callback ConsensusCallback

Returns:

Promise<boolean>

Returns true (and calls callback with acquired value) if collection was not empty. Otherwise returns false.

add

Adds a value to the collection

Signature:

add(value: T): Promise<void>;

Parameters

List of parameters
Parameter Type Description
value T

Returns:

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

List of parameters
Parameter Type Description
callback ConsensusCallback

Returns:

Promise<void>