OldestClientObserver Class
The OldestClientObserver
is a utility inspect if the local client is the oldest amongst connected clients (in terms of when they connected) and watch for changes.
It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
To use, import via @fluid-experimental/oldest-client-observer/legacy
.
For more information about our API support guarantees, see here.
Signature
export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver
Extends: TypedEventEmitter<IOldestClientObserverEvents>
Implements: IOldestClientObserver
Remarks
### Creation
The OldestClientObserver
constructor takes an IOldestClientObservable
. This is most easily satisfied with either an IContainerRuntime
or an IFluidDataStoreRuntime
:
// E.g. from within a BaseContainerRuntimeFactory:
protected async containerHasInitialized(runtime: IContainerRuntime) {
const oldestClientObserver = new OldestClientObserver(runtime);
// ...
}
// From within a DataObject
protected async hasInitialized() {
const oldestClientObserver = new OldestClientObserver(this.runtime);
// ...
}
### Usage
To check if the local client is the oldest, use the isOldest()
method.
if (oldestClientObserver.isOldest()) {
console.log("I'm the oldest");
} else {
console.log("Someone else is older");
}
### Eventing
OldestClientObserver
is an EventEmitter
, and will emit events when the local client becomes the oldest and when it is no longer the oldest.
oldestClientObserver.on("becameOldest", () => {
console.log("I'm the oldest now");
});
oldestClientObserver.on("lostOldest", () => {
console.log("I'm not the oldest anymore");
});
Constructors
Constructor | Alerts | Description |
---|---|---|
(constructor)(observable) | Alpha |
Constructs a new instance of the OldestClientObserver class |
Constructor Details
(constructor)
Constructs a new instance of the OldestClientObserver
class
To use, import via @fluid-experimental/oldest-client-observer/alpha
.
For more information about our API support guarantees, see here.
Signature
constructor(observable: IOldestClientObservable);
Parameters
Parameter | Type | Description |
---|---|---|
observable | IOldestClientObservable |