You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Task functions can only take zero or 1 parameter, so if more than one piece of data is needed as payload, pass an object with all the data, as the last example does.
126
+
123
127
## Shared Workers
124
128
125
129
Shared workers are also supported through the same `AsyncWorker` class. Note, however, the following key differences:
@@ -139,6 +143,9 @@ self.onconnect = (ev) => {
139
143
140
144
## Bi-Directional Communication
141
145
146
+
> **🕓 TL;DR**
147
+
> It's OK for workers to transmit intermediate results like progress reports and partial results. It is not recommended for the main thread to have to send data to a paused task. Promises in work item objects resolve once the `QueueingOptions.processMessage()` function returns `true`.
148
+
142
149
The default functionality is fine for many cases: A worker task is started, the user interface waits for its
143
150
completion and when the task finishes, the work item's `promise` property spits out the resultant object when awaited.
This is it. Bi-directional communcation is fully set up.
224
+
This is it. Bi-directional communication is fully set up.
218
225
219
226
### How About Sending Something Back?
220
227
@@ -246,6 +253,31 @@ export const myWorker = {
246
253
Inside `processMessage`, do `myWorkerController.enqueue.supplyMissingOrUpdatedDataWhileInTheAir(theData, { outOfOrder: true })`
247
254
and hope for the best.
248
255
256
+
## Worker Task Cancellation
257
+
258
+
To fully understand, read [this topic](#cancellationsource) in the section about synchronization objects (coming up next), and also [this other topic about WorkItem class](#the-workitem-class).
259
+
260
+
To use a cancellation token, specify the `cancellable` option when the task is enqueued:
0 commit comments