@fluid-experimental/oldest-client-observer 2.0.0-dev-rc.1.0.0.224419
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +11 -0
- package/CHANGELOG.md +144 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/oldest-client-observer.api.md +54 -0
- package/dist/index.cjs +10 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/interfaces.cjs +7 -0
- package/dist/interfaces.cjs.map +1 -0
- package/dist/interfaces.d.ts +42 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/oldest-client-observer-alpha.d.ts +111 -0
- package/dist/oldest-client-observer-beta.d.ts +17 -0
- package/dist/oldest-client-observer-public.d.ts +17 -0
- package/dist/oldest-client-observer-untrimmed.d.ts +111 -0
- package/dist/oldestClientObserver.cjs +123 -0
- package/dist/oldestClientObserver.cjs.map +1 -0
- package/dist/oldestClientObserver.d.ts +72 -0
- package/dist/oldestClientObserver.d.ts.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.mts +7 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +6 -0
- package/lib/index.mjs.map +1 -0
- package/lib/interfaces.d.mts +42 -0
- package/lib/interfaces.d.mts.map +1 -0
- package/lib/interfaces.mjs +6 -0
- package/lib/interfaces.mjs.map +1 -0
- package/lib/oldest-client-observer-alpha.d.mts +111 -0
- package/lib/oldest-client-observer-beta.d.mts +17 -0
- package/lib/oldest-client-observer-public.d.mts +17 -0
- package/lib/oldest-client-observer-untrimmed.d.mts +111 -0
- package/lib/oldestClientObserver.d.mts +72 -0
- package/lib/oldestClientObserver.d.mts.map +1 -0
- package/lib/oldestClientObserver.mjs +119 -0
- package/lib/oldestClientObserver.mjs.map +1 -0
- package/package.json +120 -0
- package/prettier.config.cjs +8 -0
- package/src/index.ts +12 -0
- package/src/interfaces.ts +51 -0
- package/src/oldestClientObserver.ts +138 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.OldestClientObserver = void 0;
|
|
8
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
9
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
10
|
+
const container_definitions_1 = require("@fluidframework/container-definitions");
|
|
11
|
+
/**
|
|
12
|
+
* The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
|
|
13
|
+
* terms of when they connected) and watch for changes.
|
|
14
|
+
*
|
|
15
|
+
* It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* ### Creation
|
|
19
|
+
*
|
|
20
|
+
* The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with
|
|
21
|
+
* either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:
|
|
22
|
+
*
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // E.g. from within a BaseContainerRuntimeFactory:
|
|
25
|
+
* protected async containerHasInitialized(runtime: IContainerRuntime) {
|
|
26
|
+
* const oldestClientObserver = new OldestClientObserver(runtime);
|
|
27
|
+
* // ...
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // From within a DataObject
|
|
33
|
+
* protected async hasInitialized() {
|
|
34
|
+
* const oldestClientObserver = new OldestClientObserver(this.runtime);
|
|
35
|
+
* // ...
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* ### Usage
|
|
40
|
+
*
|
|
41
|
+
* To check if the local client is the oldest, use the `isOldest()` method.
|
|
42
|
+
*
|
|
43
|
+
* ```typescript
|
|
44
|
+
* if (oldestClientObserver.isOldest()) {
|
|
45
|
+
* console.log("I'm the oldest");
|
|
46
|
+
* } else {
|
|
47
|
+
* console.log("Someone else is older");
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* ### Eventing
|
|
52
|
+
*
|
|
53
|
+
* `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when
|
|
54
|
+
* it is no longer the oldest.
|
|
55
|
+
*
|
|
56
|
+
* ```typescript
|
|
57
|
+
* oldestClientObserver.on("becameOldest", () => {
|
|
58
|
+
* console.log("I'm the oldest now");
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* oldestClientObserver.on("lostOldest", () => {
|
|
62
|
+
* console.log("I'm not the oldest anymore");
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
* @alpha
|
|
66
|
+
*/
|
|
67
|
+
class OldestClientObserver extends client_utils_1.TypedEventEmitter {
|
|
68
|
+
constructor(observable) {
|
|
69
|
+
super();
|
|
70
|
+
this.observable = observable;
|
|
71
|
+
this.currentIsOldest = false;
|
|
72
|
+
this.updateOldest = () => {
|
|
73
|
+
const oldest = this.computeIsOldest();
|
|
74
|
+
if (this.currentIsOldest !== oldest) {
|
|
75
|
+
this.currentIsOldest = oldest;
|
|
76
|
+
if (oldest) {
|
|
77
|
+
this.emit("becameOldest");
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.emit("lostOldest");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.quorum = this.observable.getQuorum();
|
|
85
|
+
this.currentIsOldest = this.computeIsOldest();
|
|
86
|
+
this.quorum.on("addMember", this.updateOldest);
|
|
87
|
+
this.quorum.on("removeMember", this.updateOldest);
|
|
88
|
+
observable.on("connected", this.updateOldest);
|
|
89
|
+
observable.on("disconnected", this.updateOldest);
|
|
90
|
+
}
|
|
91
|
+
isOldest() {
|
|
92
|
+
return this.currentIsOldest;
|
|
93
|
+
}
|
|
94
|
+
computeIsOldest() {
|
|
95
|
+
// If the container is detached, we are the only ones that know about it and are the oldest by default.
|
|
96
|
+
if (this.observable.attachState === container_definitions_1.AttachState.Detached) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// If we're not connected we can't be the oldest connected client.
|
|
100
|
+
if (!this.observable.connected) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
// TODO: Clean up error code linter violations repo-wide.
|
|
104
|
+
(0, core_utils_1.assert)(this.observable.clientId !== undefined,
|
|
105
|
+
// eslint-disable-next-line unicorn/numeric-separators-style
|
|
106
|
+
0x1da /* "Client id should be set if connected" */);
|
|
107
|
+
const selfSequencedClient = this.quorum.getMember(this.observable.clientId);
|
|
108
|
+
// When in readonly mode our clientId will not be present in the quorum.
|
|
109
|
+
if (selfSequencedClient === undefined) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const members = this.quorum.getMembers();
|
|
113
|
+
for (const sequencedClient of members.values()) {
|
|
114
|
+
if (sequencedClient.sequenceNumber < selfSequencedClient.sequenceNumber) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// No member of the quorum was older
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.OldestClientObserver = OldestClientObserver;
|
|
123
|
+
//# sourceMappingURL=oldestClientObserver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oldestClientObserver.cjs","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,2DAAoD;AACpD,iFAAoE;AAQpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAa,oBACZ,SAAQ,gCAA8C;IAKtD,YAA6B,UAAmC;QAC/D,KAAK,EAAE,CAAC;QADoB,eAAU,GAAV,UAAU,CAAyB;QADxD,oBAAe,GAAY,KAAK,CAAC;QAexB,iBAAY,GAAG,GAAS,EAAE;YAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM,EAAE;gBACpC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;gBAC9B,IAAI,MAAM,EAAE;oBACX,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;iBAC1B;qBAAM;oBACN,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACxB;aACD;QACF,CAAC,CAAC;QAtBD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAcO,eAAe;QACtB,uGAAuG;QACvG,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,KAAK,mCAAW,CAAC,QAAQ,EAAE;YACzD,OAAO,IAAI,CAAC;SACZ;QAED,kEAAkE;QAClE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;YAC/B,OAAO,KAAK,CAAC;SACb;QAED,yDAAyD;QACzD,IAAA,mBAAM,EACL,IAAI,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS;QACtC,4DAA4D;QAC5D,KAAK,CAAC,4CAA4C,CAClD,CAAC;QAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5E,wEAAwE;QACxE,IAAI,mBAAmB,KAAK,SAAS,EAAE;YACtC,OAAO,KAAK,CAAC;SACb;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzC,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;YAC/C,IAAI,eAAe,CAAC,cAAc,GAAG,mBAAmB,CAAC,cAAc,EAAE;gBACxE,OAAO,KAAK,CAAC;aACb;SACD;QAED,oCAAoC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAlED,oDAkEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIOldestClientObservable,\n\tIOldestClientObserverEvents,\n\tIOldestClientObserver,\n} from \"./interfaces\";\n\n/**\n * The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in\n * terms of when they connected) and watch for changes.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with\n * either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:\n *\n * ```typescript\n * // E.g. from within a BaseContainerRuntimeFactory:\n * protected async containerHasInitialized(runtime: IContainerRuntime) {\n * const oldestClientObserver = new OldestClientObserver(runtime);\n * // ...\n * }\n * ```\n *\n * ```typescript\n * // From within a DataObject\n * protected async hasInitialized() {\n * const oldestClientObserver = new OldestClientObserver(this.runtime);\n * // ...\n * }\n * ```\n *\n * ### Usage\n *\n * To check if the local client is the oldest, use the `isOldest()` method.\n *\n * ```typescript\n * if (oldestClientObserver.isOldest()) {\n * console.log(\"I'm the oldest\");\n * } else {\n * console.log(\"Someone else is older\");\n * }\n * ```\n *\n * ### Eventing\n *\n * `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when\n * it is no longer the oldest.\n *\n * ```typescript\n * oldestClientObserver.on(\"becameOldest\", () => {\n * console.log(\"I'm the oldest now\");\n * });\n *\n * oldestClientObserver.on(\"lostOldest\", () => {\n * console.log(\"I'm not the oldest anymore\");\n * });\n * ```\n * @alpha\n */\nexport class OldestClientObserver\n\textends TypedEventEmitter<IOldestClientObserverEvents>\n\timplements IOldestClientObserver\n{\n\tprivate readonly quorum: IQuorumClients;\n\tprivate currentIsOldest: boolean = false;\n\tconstructor(private readonly observable: IOldestClientObservable) {\n\t\tsuper();\n\t\tthis.quorum = this.observable.getQuorum();\n\t\tthis.currentIsOldest = this.computeIsOldest();\n\t\tthis.quorum.on(\"addMember\", this.updateOldest);\n\t\tthis.quorum.on(\"removeMember\", this.updateOldest);\n\t\tobservable.on(\"connected\", this.updateOldest);\n\t\tobservable.on(\"disconnected\", this.updateOldest);\n\t}\n\n\tpublic isOldest(): boolean {\n\t\treturn this.currentIsOldest;\n\t}\n\n\tprivate readonly updateOldest = (): void => {\n\t\tconst oldest = this.computeIsOldest();\n\t\tif (this.currentIsOldest !== oldest) {\n\t\t\tthis.currentIsOldest = oldest;\n\t\t\tif (oldest) {\n\t\t\t\tthis.emit(\"becameOldest\");\n\t\t\t} else {\n\t\t\t\tthis.emit(\"lostOldest\");\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate computeIsOldest(): boolean {\n\t\t// If the container is detached, we are the only ones that know about it and are the oldest by default.\n\t\tif (this.observable.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If we're not connected we can't be the oldest connected client.\n\t\tif (!this.observable.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\t\tassert(\n\t\t\tthis.observable.clientId !== undefined,\n\t\t\t// eslint-disable-next-line unicorn/numeric-separators-style\n\t\t\t0x1da /* \"Client id should be set if connected\" */,\n\t\t);\n\n\t\tconst selfSequencedClient = this.quorum.getMember(this.observable.clientId);\n\t\t// When in readonly mode our clientId will not be present in the quorum.\n\t\tif (selfSequencedClient === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst members = this.quorum.getMembers();\n\t\tfor (const sequencedClient of members.values()) {\n\t\t\tif (sequencedClient.sequenceNumber < selfSequencedClient.sequenceNumber) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// No member of the quorum was older\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
6
|
+
import { IOldestClientObservable, IOldestClientObserverEvents, IOldestClientObserver } from "./interfaces";
|
|
7
|
+
/**
|
|
8
|
+
* The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
|
|
9
|
+
* terms of when they connected) and watch for changes.
|
|
10
|
+
*
|
|
11
|
+
* It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* ### Creation
|
|
15
|
+
*
|
|
16
|
+
* The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with
|
|
17
|
+
* either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // E.g. from within a BaseContainerRuntimeFactory:
|
|
21
|
+
* protected async containerHasInitialized(runtime: IContainerRuntime) {
|
|
22
|
+
* const oldestClientObserver = new OldestClientObserver(runtime);
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // From within a DataObject
|
|
29
|
+
* protected async hasInitialized() {
|
|
30
|
+
* const oldestClientObserver = new OldestClientObserver(this.runtime);
|
|
31
|
+
* // ...
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* ### Usage
|
|
36
|
+
*
|
|
37
|
+
* To check if the local client is the oldest, use the `isOldest()` method.
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* if (oldestClientObserver.isOldest()) {
|
|
41
|
+
* console.log("I'm the oldest");
|
|
42
|
+
* } else {
|
|
43
|
+
* console.log("Someone else is older");
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* ### Eventing
|
|
48
|
+
*
|
|
49
|
+
* `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when
|
|
50
|
+
* it is no longer the oldest.
|
|
51
|
+
*
|
|
52
|
+
* ```typescript
|
|
53
|
+
* oldestClientObserver.on("becameOldest", () => {
|
|
54
|
+
* console.log("I'm the oldest now");
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* oldestClientObserver.on("lostOldest", () => {
|
|
58
|
+
* console.log("I'm not the oldest anymore");
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
* @alpha
|
|
62
|
+
*/
|
|
63
|
+
export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
|
|
64
|
+
private readonly observable;
|
|
65
|
+
private readonly quorum;
|
|
66
|
+
private currentIsOldest;
|
|
67
|
+
constructor(observable: IOldestClientObservable);
|
|
68
|
+
isOldest(): boolean;
|
|
69
|
+
private readonly updateOldest;
|
|
70
|
+
private computeIsOldest;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=oldestClientObserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oldestClientObserver.d.ts","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBAAa,oBACZ,SAAQ,iBAAiB,CAAC,2BAA2B,CACrD,YAAW,qBAAqB;IAIpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAkB;gBACZ,UAAU,EAAE,uBAAuB;IAUzD,QAAQ,IAAI,OAAO;IAI1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAU3B;IAEF,OAAO,CAAC,eAAe;CAkCvB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.38.3"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export { IOldestClientObservable, IOldestClientObservableEvents, IOldestClientObserver, IOldestClientObserverEvents, } from "./interfaces.mjs";
|
|
6
|
+
export { OldestClientObserver } from "./oldestClientObserver.mjs";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EACN,uBAAuB,EACvB,6BAA6B,EAC7B,qBAAqB,EACrB,2BAA2B,GAC3B;OACM,EAAE,oBAAoB,EAAE"}
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAQI,EAAE,oBAAoB,EAAE","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tIOldestClientObservable,\n\tIOldestClientObservableEvents,\n\tIOldestClientObserver,\n\tIOldestClientObserverEvents,\n} from \"./interfaces\";\nexport { OldestClientObserver } from \"./oldestClientObserver\";\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IEvent, IEventProvider } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { AttachState } from "@fluidframework/container-definitions";
|
|
7
|
+
import { IQuorumClients } from "@fluidframework/protocol-definitions";
|
|
8
|
+
/**
|
|
9
|
+
* Events emitted by {@link IOldestClientObservable}.
|
|
10
|
+
* @alpha
|
|
11
|
+
*/
|
|
12
|
+
export interface IOldestClientObservableEvents extends IEvent {
|
|
13
|
+
(event: "connected", listener: () => void): any;
|
|
14
|
+
(event: "disconnected", listener: () => void): any;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime
|
|
18
|
+
* (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
|
|
19
|
+
* since neither is really the source of truth (they are just the only currently-available plumbing options).
|
|
20
|
+
* It's information about the connection, so the real source of truth is lower (at the connection layer).
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
export interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
|
|
24
|
+
getQuorum(): IQuorumClients;
|
|
25
|
+
attachState: AttachState;
|
|
26
|
+
connected: boolean;
|
|
27
|
+
clientId: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Events emitted by {@link IOldestClientObservable}.
|
|
31
|
+
* @alpha
|
|
32
|
+
*/
|
|
33
|
+
export interface IOldestClientObserverEvents extends IEvent {
|
|
34
|
+
(event: "becameOldest" | "lostOldest", listener: () => void): any;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @alpha
|
|
38
|
+
*/
|
|
39
|
+
export interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
|
|
40
|
+
isOldest(): boolean;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iCAAiC;OACjE,EAAE,WAAW,EAAE,MAAM,uCAAuC;OAC5D,EAAE,cAAc,EAAE,MAAM,sCAAsC;AAErE;;;GAGG;AACH,MAAM,WAAW,6BAA8B,SAAQ,MAAM;IAC5D,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;IAC3C,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC9C;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc,CAAC,6BAA6B,CAAC;IAC7F,SAAS,IAAI,cAAc,CAAC;IAM5B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,2BAA4B,SAAQ,MAAM;IAC1D,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,2BAA2B,CAAC;IACzF,QAAQ,IAAI,OAAO,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.mjs","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider } from \"@fluidframework/core-interfaces\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IQuorumClients } from \"@fluidframework/protocol-definitions\";\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n * @alpha\n */\nexport interface IOldestClientObservableEvents extends IEvent {\n\t(event: \"connected\", listener: () => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime\n * (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,\n * since neither is really the source of truth (they are just the only currently-available plumbing options).\n * It's information about the connection, so the real source of truth is lower (at the connection layer).\n * @alpha\n */\nexport interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {\n\tgetQuorum(): IQuorumClients;\n\t// Generic usage of attachState is a little unusual here. We will treat ourselves as \"the oldest client that\n\t// has information about this [container | data store]\", which in the case of detached data store may disagree\n\t// with whether we're the oldest client on the connected container. So in the data store case, it's only\n\t// safe use this as an indicator about rights to tasks performed against this specific data store, and not\n\t// more broadly.\n\tattachState: AttachState;\n\tconnected: boolean;\n\tclientId: string | undefined;\n}\n\n/**\n * Events emitted by {@link IOldestClientObservable}.\n * @alpha\n */\nexport interface IOldestClientObserverEvents extends IEvent {\n\t(event: \"becameOldest\" | \"lostOldest\", listener: () => void);\n}\n\n/**\n * @alpha\n */\nexport interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {\n\tisOldest(): boolean;\n}\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { AttachState } from '@fluidframework/container-definitions';
|
|
2
|
+
import { IEvent } from '@fluidframework/core-interfaces';
|
|
3
|
+
import { IEventProvider } from '@fluidframework/core-interfaces';
|
|
4
|
+
import { IQuorumClients } from '@fluidframework/protocol-definitions';
|
|
5
|
+
import { TypedEventEmitter } from '@fluid-internal/client-utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime
|
|
9
|
+
* (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
|
|
10
|
+
* since neither is really the source of truth (they are just the only currently-available plumbing options).
|
|
11
|
+
* It's information about the connection, so the real source of truth is lower (at the connection layer).
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export declare interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
|
|
15
|
+
getQuorum(): IQuorumClients;
|
|
16
|
+
attachState: AttachState;
|
|
17
|
+
connected: boolean;
|
|
18
|
+
clientId: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Events emitted by {@link IOldestClientObservable}.
|
|
23
|
+
* @alpha
|
|
24
|
+
*/
|
|
25
|
+
export declare interface IOldestClientObservableEvents extends IEvent {
|
|
26
|
+
(event: "connected", listener: () => void): any;
|
|
27
|
+
(event: "disconnected", listener: () => void): any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @alpha
|
|
32
|
+
*/
|
|
33
|
+
export declare interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
|
|
34
|
+
isOldest(): boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Events emitted by {@link IOldestClientObservable}.
|
|
39
|
+
* @alpha
|
|
40
|
+
*/
|
|
41
|
+
export declare interface IOldestClientObserverEvents extends IEvent {
|
|
42
|
+
(event: "becameOldest" | "lostOldest", listener: () => void): any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
|
|
47
|
+
* terms of when they connected) and watch for changes.
|
|
48
|
+
*
|
|
49
|
+
* It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* ### Creation
|
|
53
|
+
*
|
|
54
|
+
* The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with
|
|
55
|
+
* either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:
|
|
56
|
+
*
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // E.g. from within a BaseContainerRuntimeFactory:
|
|
59
|
+
* protected async containerHasInitialized(runtime: IContainerRuntime) {
|
|
60
|
+
* const oldestClientObserver = new OldestClientObserver(runtime);
|
|
61
|
+
* // ...
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // From within a DataObject
|
|
67
|
+
* protected async hasInitialized() {
|
|
68
|
+
* const oldestClientObserver = new OldestClientObserver(this.runtime);
|
|
69
|
+
* // ...
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* ### Usage
|
|
74
|
+
*
|
|
75
|
+
* To check if the local client is the oldest, use the `isOldest()` method.
|
|
76
|
+
*
|
|
77
|
+
* ```typescript
|
|
78
|
+
* if (oldestClientObserver.isOldest()) {
|
|
79
|
+
* console.log("I'm the oldest");
|
|
80
|
+
* } else {
|
|
81
|
+
* console.log("Someone else is older");
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* ### Eventing
|
|
86
|
+
*
|
|
87
|
+
* `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when
|
|
88
|
+
* it is no longer the oldest.
|
|
89
|
+
*
|
|
90
|
+
* ```typescript
|
|
91
|
+
* oldestClientObserver.on("becameOldest", () => {
|
|
92
|
+
* console.log("I'm the oldest now");
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* oldestClientObserver.on("lostOldest", () => {
|
|
96
|
+
* console.log("I'm not the oldest anymore");
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
* @alpha
|
|
100
|
+
*/
|
|
101
|
+
export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
|
|
102
|
+
private readonly observable;
|
|
103
|
+
private readonly quorum;
|
|
104
|
+
private currentIsOldest;
|
|
105
|
+
constructor(observable: IOldestClientObservable);
|
|
106
|
+
isOldest(): boolean;
|
|
107
|
+
private readonly updateOldest;
|
|
108
|
+
private computeIsOldest;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AttachState } from '@fluidframework/container-definitions';
|
|
2
|
+
import { IEvent } from '@fluidframework/core-interfaces';
|
|
3
|
+
import { IEventProvider } from '@fluidframework/core-interfaces';
|
|
4
|
+
import { IQuorumClients } from '@fluidframework/protocol-definitions';
|
|
5
|
+
import { TypedEventEmitter } from '@fluid-internal/client-utils';
|
|
6
|
+
|
|
7
|
+
/* Excluded from this release type: IOldestClientObservable */
|
|
8
|
+
|
|
9
|
+
/* Excluded from this release type: IOldestClientObservableEvents */
|
|
10
|
+
|
|
11
|
+
/* Excluded from this release type: IOldestClientObserver */
|
|
12
|
+
|
|
13
|
+
/* Excluded from this release type: IOldestClientObserverEvents */
|
|
14
|
+
|
|
15
|
+
/* Excluded from this release type: OldestClientObserver */
|
|
16
|
+
|
|
17
|
+
export { }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AttachState } from '@fluidframework/container-definitions';
|
|
2
|
+
import { IEvent } from '@fluidframework/core-interfaces';
|
|
3
|
+
import { IEventProvider } from '@fluidframework/core-interfaces';
|
|
4
|
+
import { IQuorumClients } from '@fluidframework/protocol-definitions';
|
|
5
|
+
import { TypedEventEmitter } from '@fluid-internal/client-utils';
|
|
6
|
+
|
|
7
|
+
/* Excluded from this release type: IOldestClientObservable */
|
|
8
|
+
|
|
9
|
+
/* Excluded from this release type: IOldestClientObservableEvents */
|
|
10
|
+
|
|
11
|
+
/* Excluded from this release type: IOldestClientObserver */
|
|
12
|
+
|
|
13
|
+
/* Excluded from this release type: IOldestClientObserverEvents */
|
|
14
|
+
|
|
15
|
+
/* Excluded from this release type: OldestClientObserver */
|
|
16
|
+
|
|
17
|
+
export { }
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { AttachState } from '@fluidframework/container-definitions';
|
|
2
|
+
import { IEvent } from '@fluidframework/core-interfaces';
|
|
3
|
+
import { IEventProvider } from '@fluidframework/core-interfaces';
|
|
4
|
+
import { IQuorumClients } from '@fluidframework/protocol-definitions';
|
|
5
|
+
import { TypedEventEmitter } from '@fluid-internal/client-utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This is to make OldestClientObserver work with either a ContainerRuntime or an IFluidDataStoreRuntime
|
|
9
|
+
* (both expose the relevant API surface and eventing). However, really this info probably shouldn't live on either,
|
|
10
|
+
* since neither is really the source of truth (they are just the only currently-available plumbing options).
|
|
11
|
+
* It's information about the connection, so the real source of truth is lower (at the connection layer).
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export declare interface IOldestClientObservable extends IEventProvider<IOldestClientObservableEvents> {
|
|
15
|
+
getQuorum(): IQuorumClients;
|
|
16
|
+
attachState: AttachState;
|
|
17
|
+
connected: boolean;
|
|
18
|
+
clientId: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Events emitted by {@link IOldestClientObservable}.
|
|
23
|
+
* @alpha
|
|
24
|
+
*/
|
|
25
|
+
export declare interface IOldestClientObservableEvents extends IEvent {
|
|
26
|
+
(event: "connected", listener: () => void): any;
|
|
27
|
+
(event: "disconnected", listener: () => void): any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @alpha
|
|
32
|
+
*/
|
|
33
|
+
export declare interface IOldestClientObserver extends IEventProvider<IOldestClientObserverEvents> {
|
|
34
|
+
isOldest(): boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Events emitted by {@link IOldestClientObservable}.
|
|
39
|
+
* @alpha
|
|
40
|
+
*/
|
|
41
|
+
export declare interface IOldestClientObserverEvents extends IEvent {
|
|
42
|
+
(event: "becameOldest" | "lostOldest", listener: () => void): any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
|
|
47
|
+
* terms of when they connected) and watch for changes.
|
|
48
|
+
*
|
|
49
|
+
* It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* ### Creation
|
|
53
|
+
*
|
|
54
|
+
* The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with
|
|
55
|
+
* either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:
|
|
56
|
+
*
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // E.g. from within a BaseContainerRuntimeFactory:
|
|
59
|
+
* protected async containerHasInitialized(runtime: IContainerRuntime) {
|
|
60
|
+
* const oldestClientObserver = new OldestClientObserver(runtime);
|
|
61
|
+
* // ...
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // From within a DataObject
|
|
67
|
+
* protected async hasInitialized() {
|
|
68
|
+
* const oldestClientObserver = new OldestClientObserver(this.runtime);
|
|
69
|
+
* // ...
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* ### Usage
|
|
74
|
+
*
|
|
75
|
+
* To check if the local client is the oldest, use the `isOldest()` method.
|
|
76
|
+
*
|
|
77
|
+
* ```typescript
|
|
78
|
+
* if (oldestClientObserver.isOldest()) {
|
|
79
|
+
* console.log("I'm the oldest");
|
|
80
|
+
* } else {
|
|
81
|
+
* console.log("Someone else is older");
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* ### Eventing
|
|
86
|
+
*
|
|
87
|
+
* `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when
|
|
88
|
+
* it is no longer the oldest.
|
|
89
|
+
*
|
|
90
|
+
* ```typescript
|
|
91
|
+
* oldestClientObserver.on("becameOldest", () => {
|
|
92
|
+
* console.log("I'm the oldest now");
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* oldestClientObserver.on("lostOldest", () => {
|
|
96
|
+
* console.log("I'm not the oldest anymore");
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
* @alpha
|
|
100
|
+
*/
|
|
101
|
+
export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
|
|
102
|
+
private readonly observable;
|
|
103
|
+
private readonly quorum;
|
|
104
|
+
private currentIsOldest;
|
|
105
|
+
constructor(observable: IOldestClientObservable);
|
|
106
|
+
isOldest(): boolean;
|
|
107
|
+
private readonly updateOldest;
|
|
108
|
+
private computeIsOldest;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { }
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
6
|
+
import { IOldestClientObservable, IOldestClientObserverEvents, IOldestClientObserver } from "./interfaces.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* The `OldestClientObserver` is a utility inspect if the local client is the oldest amongst connected clients (in
|
|
9
|
+
* terms of when they connected) and watch for changes.
|
|
10
|
+
*
|
|
11
|
+
* It is still experimental and under development. Please do try it out, but expect breaking changes in the future.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* ### Creation
|
|
15
|
+
*
|
|
16
|
+
* The `OldestClientObserver` constructor takes an `IOldestClientObservable`. This is most easily satisfied with
|
|
17
|
+
* either an `IContainerRuntime` or an `IFluidDataStoreRuntime`:
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // E.g. from within a BaseContainerRuntimeFactory:
|
|
21
|
+
* protected async containerHasInitialized(runtime: IContainerRuntime) {
|
|
22
|
+
* const oldestClientObserver = new OldestClientObserver(runtime);
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // From within a DataObject
|
|
29
|
+
* protected async hasInitialized() {
|
|
30
|
+
* const oldestClientObserver = new OldestClientObserver(this.runtime);
|
|
31
|
+
* // ...
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* ### Usage
|
|
36
|
+
*
|
|
37
|
+
* To check if the local client is the oldest, use the `isOldest()` method.
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* if (oldestClientObserver.isOldest()) {
|
|
41
|
+
* console.log("I'm the oldest");
|
|
42
|
+
* } else {
|
|
43
|
+
* console.log("Someone else is older");
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* ### Eventing
|
|
48
|
+
*
|
|
49
|
+
* `OldestClientObserver` is an `EventEmitter`, and will emit events when the local client becomes the oldest and when
|
|
50
|
+
* it is no longer the oldest.
|
|
51
|
+
*
|
|
52
|
+
* ```typescript
|
|
53
|
+
* oldestClientObserver.on("becameOldest", () => {
|
|
54
|
+
* console.log("I'm the oldest now");
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* oldestClientObserver.on("lostOldest", () => {
|
|
58
|
+
* console.log("I'm not the oldest anymore");
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
* @alpha
|
|
62
|
+
*/
|
|
63
|
+
export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver {
|
|
64
|
+
private readonly observable;
|
|
65
|
+
private readonly quorum;
|
|
66
|
+
private currentIsOldest;
|
|
67
|
+
constructor(observable: IOldestClientObservable);
|
|
68
|
+
isOldest(): boolean;
|
|
69
|
+
private readonly updateOldest;
|
|
70
|
+
private computeIsOldest;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=oldestClientObserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oldestClientObserver.d.ts","sourceRoot":"","sources":["../src/oldestClientObserver.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OAIzD,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBAAa,oBACZ,SAAQ,iBAAiB,CAAC,2BAA2B,CACrD,YAAW,qBAAqB;IAIpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAkB;gBACZ,UAAU,EAAE,uBAAuB;IAUzD,QAAQ,IAAI,OAAO;IAI1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAU3B;IAEF,OAAO,CAAC,eAAe;CAkCvB"}
|