Skip to content

Commit 1f291bc

Browse files
authored
re-add queuing for getResource calls (#9031)
fix #8998
1 parent 6fe14dc commit 1f291bc

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/util/actor.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Actor {
5353
* @param targetMapId A particular mapId to which to send this message.
5454
* @private
5555
*/
56-
send(type: string, data: mixed, callback: ?Function, targetMapId: ?string): ?Cancelable {
56+
send(type: string, data: mixed, callback: ?Function, targetMapId: ?string, mustQueue: boolean = false): ?Cancelable {
5757
// We're using a string ID instead of numbers because they are being used as object keys
5858
// anyway, and thus stringified implicitly. We use random IDs because an actor may receive
5959
// message from multiple other actors which could run in different execution context. A
@@ -68,6 +68,7 @@ class Actor {
6868
type,
6969
hasCallback: !!callback,
7070
targetMapId,
71+
mustQueue,
7172
sourceMapId: this.mapId,
7273
data: serialize(data, buffers)
7374
}, buffers);
@@ -110,20 +111,20 @@ class Actor {
110111
cancel();
111112
}
112113
} else {
113-
// In workers, store the tasks that we need to process before actually processing them. This
114-
// is necessary because we want to keep receiving messages, and in particular,
115-
// <cancel> messages. Some tasks may take a while in the worker thread, so before
116-
// executing the next task in our queue, postMessage preempts this and <cancel>
117-
// messages can be processed. We're using a MessageChannel object to get throttle the
118-
// process() flow to one at a time.
119-
this.tasks[id] = data;
120-
this.taskQueue.push(id);
121-
if (isWorker()) {
114+
if (isWorker() || data.mustQueue) {
115+
// In workers, store the tasks that we need to process before actually processing them. This
116+
// is necessary because we want to keep receiving messages, and in particular,
117+
// <cancel> messages. Some tasks may take a while in the worker thread, so before
118+
// executing the next task in our queue, postMessage preempts this and <cancel>
119+
// messages can be processed. We're using a MessageChannel object to get throttle the
120+
// process() flow to one at a time.
121+
this.tasks[id] = data;
122+
this.taskQueue.push(id);
122123
this.invoker.trigger();
123124
} else {
124125
// In the main thread, process messages immediately so that other work does not slip in
125126
// between getting partial data back from workers.
126-
this.process();
127+
this.processTask(id, data);
127128
}
128129
}
129130
}
@@ -146,6 +147,10 @@ class Actor {
146147
return;
147148
}
148149

150+
this.processTask(id, task);
151+
}
152+
153+
processTask(id: number, task: any) {
149154
if (task.type === '<response>') {
150155
// The done() function in the counterpart has been called, and we are now
151156
// firing the callback in the originating actor, if there is one.

src/util/ajax.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ export const makeRequest = function(requestParameters: RequestParameters, callba
230230
return makeFetchRequest(requestParameters, callback);
231231
}
232232
if (isWorker() && self.worker && self.worker.actor) {
233-
return self.worker.actor.send('getResource', requestParameters, callback);
233+
const queueOnMainThread = true;
234+
return self.worker.actor.send('getResource', requestParameters, callback, undefined, queueOnMainThread);
234235
}
235236
}
236237
return makeXMLHttpRequest(requestParameters, callback);

0 commit comments

Comments
 (0)