@@ -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 : ? string ) : ?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,7 +111,7 @@ class Actor {
110
111
cancel ( ) ;
111
112
}
112
113
} else {
113
- if ( isWorker ( ) || data . type === 'getResource' ) {
114
+ if ( isWorker ( ) || data . mustQueue ) {
114
115
// In workers, store the tasks that we need to process before actually processing them. This
115
116
// is necessary because we want to keep receiving messages, and in particular,
116
117
// <cancel> messages. Some tasks may take a while in the worker thread, so before
@@ -123,31 +124,33 @@ class Actor {
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 ( id , data) ;
127
+ this . processTask ( id , data) ;
127
128
}
128
129
}
129
130
}
130
131
131
- process ( id : number , task : any ) {
132
- if ( id === undefined && task === undefined ) {
133
- if ( ! this . taskQueue . length ) {
134
- return ;
135
- }
136
- id = this.taskQueue.shift();
137
- task = this.tasks[id];
138
- delete this.tasks[id];
139
- // Schedule another process call if we know there's more to process _before_ invoking the
140
- // current task. This is necessary so that processing continues even if the current task
141
- // doesn't execute successfully.
142
- if (this.taskQueue.length) {
143
- this . invoker . trigger ( ) ;
144
- }
145
- if (!task) {
146
- // If the task ID doesn't have associated task data anymore, it was canceled.
147
- return ;
148
- }
132
+ process ( ) {
133
+ if ( ! this . taskQueue . length ) {
134
+ return ;
149
135
}
136
+ const id = this.taskQueue.shift();
137
+ const task = this.tasks[id];
138
+ delete this.tasks[id];
139
+ // Schedule another process call if we know there's more to process _before_ invoking the
140
+ // current task. This is necessary so that processing continues even if the current task
141
+ // doesn't execute successfully.
142
+ if (this.taskQueue.length) {
143
+ this . invoker . trigger ( ) ;
144
+ }
145
+ if (!task) {
146
+ // If the task ID doesn't have associated task data anymore, it was canceled.
147
+ return ;
148
+ }
149
+
150
+ this.processTask(id, task);
151
+ }
150
152
153
+ processTask ( id : number , task : any ) {
151
154
if ( task . type === '<response>' ) {
152
155
// The done() function in the counterpart has been called, and we are now
153
156
// firing the callback in the originating actor, if there is one.
0 commit comments