@@ -53,7 +53,7 @@ class Actor {
53
53
* @param targetMapId A particular mapId to which to send this message.
54
54
* @private
55
55
*/
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 {
57
57
// We're using a string ID instead of numbers because they are being used as object keys
58
58
// anyway, and thus stringified implicitly. We use random IDs because an actor may receive
59
59
// message from multiple other actors which could run in different execution context. A
@@ -68,6 +68,7 @@ class Actor {
68
68
type ,
69
69
hasCallback : ! ! callback ,
70
70
targetMapId ,
71
+ mustQueue ,
71
72
sourceMapId : this . mapId ,
72
73
data : serialize ( data , buffers )
73
74
} , buffers);
@@ -110,20 +111,20 @@ class Actor {
110
111
cancel ( ) ;
111
112
}
112
113
} 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 ) ;
122
123
this . invoker . trigger ( ) ;
123
124
} else {
124
125
// In the main thread, process messages immediately so that other work does not slip in
125
126
// between getting partial data back from workers.
126
- this . process ( ) ;
127
+ this . processTask ( id , data ) ;
127
128
}
128
129
}
129
130
}
@@ -146,6 +147,10 @@ class Actor {
146
147
return ;
147
148
}
148
149
150
+ this.processTask(id, task);
151
+ }
152
+
153
+ processTask ( id : number , task : any ) {
149
154
if ( task . type === '<response>' ) {
150
155
// The done() function in the counterpart has been called, and we are now
151
156
// firing the callback in the originating actor, if there is one.
0 commit comments