@fluidframework/agent-scheduler 2.0.0-internal.3.0.1 → 2.0.0-internal.3.1.0

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.
@@ -8,58 +8,58 @@ import { TypedEventEmitter } from "@fluidframework/common-utils";
8
8
  import { IAgentScheduler } from "./agent";
9
9
 
10
10
  export interface ITaskSubscriptionEvents extends IEvent {
11
- (event: "gotTask" | "lostTask", listener: () => void);
11
+ (event: "gotTask" | "lostTask", listener: () => void);
12
12
  }
13
13
 
14
14
  /**
15
15
  * TaskSubscription works with an AgentScheduler to make it easier to monitor a specific task ownership.
16
16
  */
17
17
  export class TaskSubscription extends TypedEventEmitter<ITaskSubscriptionEvents> {
18
- private subscribed: boolean = false;
18
+ private subscribed: boolean = false;
19
19
 
20
- /**
21
- * @param agentScheduler - The AgentScheduler that will be subscribed against
22
- * @param taskId - The string ID of the task to subscribe against
23
- */
24
- constructor(private readonly agentScheduler: IAgentScheduler, public readonly taskId: string) {
25
- super();
26
- agentScheduler.on("picked", (_taskId: string) => {
27
- if (_taskId === this.taskId) {
28
- this.emit("gotTask");
29
- }
30
- });
31
- agentScheduler.on("released", (_taskId: string) => {
32
- if (_taskId === this.taskId) {
33
- this.emit("lostTask");
34
- }
35
- });
36
- agentScheduler.on("lost", (_taskId: string) => {
37
- if (_taskId === this.taskId) {
38
- this.emit("lostTask");
39
- }
40
- });
41
- }
20
+ /**
21
+ * @param agentScheduler - The AgentScheduler that will be subscribed against
22
+ * @param taskId - The string ID of the task to subscribe against
23
+ */
24
+ constructor(private readonly agentScheduler: IAgentScheduler, public readonly taskId: string) {
25
+ super();
26
+ agentScheduler.on("picked", (_taskId: string) => {
27
+ if (_taskId === this.taskId) {
28
+ this.emit("gotTask");
29
+ }
30
+ });
31
+ agentScheduler.on("released", (_taskId: string) => {
32
+ if (_taskId === this.taskId) {
33
+ this.emit("lostTask");
34
+ }
35
+ });
36
+ agentScheduler.on("lost", (_taskId: string) => {
37
+ if (_taskId === this.taskId) {
38
+ this.emit("lostTask");
39
+ }
40
+ });
41
+ }
42
42
 
43
- /**
44
- * Check if currently holding ownership of the task.
45
- * @returns true if currently the task owner, false otherwise.
46
- */
47
- public haveTask() {
48
- return this.agentScheduler.pickedTasks().includes(this.taskId);
49
- }
43
+ /**
44
+ * Check if currently holding ownership of the task.
45
+ * @returns true if currently the task owner, false otherwise.
46
+ */
47
+ public haveTask() {
48
+ return this.agentScheduler.pickedTasks().includes(this.taskId);
49
+ }
50
50
 
51
- /**
52
- * Volunteer for the task. By default, the TaskSubscription will only watch the task and not volunteer.
53
- * This is safe to call multiple times across multiple TaskSubscriptions.
54
- */
55
- public volunteer() {
56
- if (!this.subscribed) {
57
- // AgentScheduler throws if the same task is picked twice but we don't care because our
58
- // worker does nothing. We only care that the AgentScheduler is trying to pick.
59
- // We also don't care if we throw due to failing the interactive check, because then we'll
60
- // just appear to never get the task.
61
- this.agentScheduler.pick(this.taskId, async () => { }).catch(() => { });
62
- this.subscribed = true;
63
- }
64
- }
51
+ /**
52
+ * Volunteer for the task. By default, the TaskSubscription will only watch the task and not volunteer.
53
+ * This is safe to call multiple times across multiple TaskSubscriptions.
54
+ */
55
+ public volunteer() {
56
+ if (!this.subscribed) {
57
+ // AgentScheduler throws if the same task is picked twice but we don't care because our
58
+ // worker does nothing. We only care that the AgentScheduler is trying to pick.
59
+ // We also don't care if we throw due to failing the interactive check, because then we'll
60
+ // just appear to never get the task.
61
+ this.agentScheduler.pick(this.taskId, async () => {}).catch(() => {});
62
+ this.subscribed = true;
63
+ }
64
+ }
65
65
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "module": "esnext",
6
+ },
7
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "exclude": [
4
- "src/test/**/*"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "./src",
8
- "outDir": "./dist",
9
- "composite": true
10
- },
11
- "include": [
12
- "src/**/*"
13
- ]
14
- }
2
+ "extends": "@fluidframework/build-common/ts-common-config.json",
3
+ "exclude": ["src/test/**/*"],
4
+ "compilerOptions": {
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ "composite": true,
8
+ },
9
+ "include": ["src/**/*"],
10
+ }