@fluidframework/task-manager 2.0.0-internal.4.2.1 → 2.0.0-internal.4.3.1
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/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +114 -4
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/taskManager.d.ts +2 -85
- package/dist/taskManager.d.ts.map +1 -1
- package/dist/taskManager.js +3 -86
- package/dist/taskManager.js.map +1 -1
- package/lib/index.d.ts +7 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +114 -4
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/interfaces.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/taskManager.d.ts +2 -85
- package/lib/taskManager.d.ts.map +1 -1
- package/lib/taskManager.js +3 -86
- package/lib/taskManager.js.map +1 -1
- package/package.json +14 -14
- package/src/index.ts +8 -1
- package/src/interfaces.ts +117 -4
- package/src/packageVersion.ts +1 -1
- package/src/taskManager.ts +3 -86
package/src/taskManager.ts
CHANGED
|
@@ -60,92 +60,9 @@ const snapshotFileName = "header";
|
|
|
60
60
|
const placeholderClientId = "placeholder";
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* {@inheritDoc ITaskManager}
|
|
64
64
|
*
|
|
65
|
-
* @
|
|
66
|
-
*
|
|
67
|
-
* ### Creation
|
|
68
|
-
*
|
|
69
|
-
* To create a `TaskManager`, call the static create method:
|
|
70
|
-
*
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const taskManager = TaskManager.create(this.runtime, id);
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* ### Usage
|
|
76
|
-
*
|
|
77
|
-
* To volunteer for a task, use the `volunteerForTask()` method. This returns a Promise that will resolve once the
|
|
78
|
-
* client has acquired exclusive rights to run the task, or reject if the client is removed from the queue without
|
|
79
|
-
* acquiring the rights.
|
|
80
|
-
*
|
|
81
|
-
* ```typescript
|
|
82
|
-
* taskManager.volunteerForTask("NameOfTask")
|
|
83
|
-
* .then(() => { doTheTask(); })
|
|
84
|
-
* .catch((err) => { console.error(err); });
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* Alternatively, you can indefinitely volunteer for a task with the synchronous `subscribeToTask()` method. This
|
|
88
|
-
* method does not return a value, therefore you need to rely on eventing to know when you have acquired the rights
|
|
89
|
-
* to run the task (see below).
|
|
90
|
-
*
|
|
91
|
-
* ```typescript
|
|
92
|
-
* taskManager.subscribeToTask("NameOfTask");
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* To check if the local client is currently subscribed to a task, use the `subscribed()` method.
|
|
96
|
-
* ```typescript
|
|
97
|
-
* if (taskManager.subscribed("NameOfTask")) {
|
|
98
|
-
* console.log("This client is currently subscribed to the task.");
|
|
99
|
-
* }
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* To release the rights to the task, use the `abandon()` method. The next client in the queue will then get the
|
|
103
|
-
* rights to run the task.
|
|
104
|
-
*
|
|
105
|
-
* ```typescript
|
|
106
|
-
* taskManager.abandon("NameOfTask");
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* To inspect your state in the queue, you can use the `queued()` and `assigned()` methods.
|
|
110
|
-
*
|
|
111
|
-
* ```typescript
|
|
112
|
-
* if (taskManager.queued("NameOfTask")) {
|
|
113
|
-
* console.log("This client is somewhere in the queue, potentially even having the task assignment.");
|
|
114
|
-
* }
|
|
115
|
-
*
|
|
116
|
-
* if (taskManager.assigned("NameOfTask")) {
|
|
117
|
-
* console.log("This client currently has the rights to run the task");
|
|
118
|
-
* }
|
|
119
|
-
* ```
|
|
120
|
-
*
|
|
121
|
-
* To signal to other connected clients that a task is completed, use the `complete()` method. This will release all
|
|
122
|
-
* clients from the queue and emit the "completed" event.
|
|
123
|
-
*
|
|
124
|
-
* ```typescript
|
|
125
|
-
* taskManager.complete("NameOfTask");
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* ### Eventing
|
|
129
|
-
*
|
|
130
|
-
* `TaskManager` is an `EventEmitter`, and will emit events when a task is assigned to the client, when the task
|
|
131
|
-
* assignment is lost, and when a task was completed by another client.
|
|
132
|
-
*
|
|
133
|
-
* ```typescript
|
|
134
|
-
* taskManager.on("assigned", (taskId: string) => {
|
|
135
|
-
* console.log(`Client was assigned task: ${taskId}`);
|
|
136
|
-
* });
|
|
137
|
-
*
|
|
138
|
-
* taskManager.on("lost", (taskId: string) => {
|
|
139
|
-
* console.log(`Client released task: ${taskId}`);
|
|
140
|
-
* });
|
|
141
|
-
*
|
|
142
|
-
* taskManager.on("completed", (taskId: string) => {
|
|
143
|
-
* console.log(`Another client completed task: ${taskId}`);
|
|
144
|
-
* });
|
|
145
|
-
* ```
|
|
146
|
-
*
|
|
147
|
-
* These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as
|
|
148
|
-
* when using the `subscribeToTask()` method.
|
|
65
|
+
* @sealed
|
|
149
66
|
*/
|
|
150
67
|
export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {
|
|
151
68
|
/**
|
|
@@ -861,6 +778,6 @@ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITa
|
|
|
861
778
|
}
|
|
862
779
|
|
|
863
780
|
public applyStashedOp() {
|
|
864
|
-
|
|
781
|
+
// do nothing...
|
|
865
782
|
}
|
|
866
783
|
}
|