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.

This API is provided for existing users, but is not recommended for new users.

To use, import via @fluidframework/ordered-collection/legacy.

For more information about our API support guarantees, see here .

Signature

export interface IConsensusOrderedCollection<T = any> extends ISharedObject<IConsensusOrderedCollectionEvents<T>>

Extends: ISharedObject <IConsensusOrderedCollectionEvents <T>>

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 Alerts Return Type Description
acquire(callback) Alpha Promise<boolean> Retrieves a value from the collection.
add(value) Alpha Promise<void> Adds a value to the collection
waitAndAcquire(callback) Alpha 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.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/ordered-collection/alpha.

For more information about our API support guarantees, see here .

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

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/ordered-collection/alpha.

For more information about our API support guarantees, see here .

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.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/ordered-collection/alpha.

For more information about our API support guarantees, see here .

Signature

waitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;

Parameters

Parameter Type Description
callback ConsensusCallback<T>

Returns

Return type: Promise<void>