Skip to content

Commit

Permalink
fix(WebWorker): Don't send messages when the buffer is empty
Browse files Browse the repository at this point in the history
Closes #4138
  • Loading branch information
jteplitz authored and mhevery committed Oct 29, 2015
1 parent 1de2d29 commit 8485ef9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ abstract class GenericMessageBusSink implements MessageBusSink {
void attachToZone(NgZone zone) {
_zone = zone;
_zone.overrideOnEventDone(() {
sendMessages(_messageBuffer);
_messageBuffer.clear();
if (_messageBuffer.length > 0) {
sendMessages(_messageBuffer);
_messageBuffer.clear();
}
}, false);
}

Expand Down
7 changes: 4 additions & 3 deletions modules/angular2/src/web_workers/shared/post_message_bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export class PostMessageBusSink implements MessageBusSink {
}

private _handleOnEventDone() {
// TODO: Send all buffered messages in one postMessage call
this._sendMessages(this._messageBuffer);
this._messageBuffer = [];
if (this._messageBuffer.length > 0) {
this._sendMessages(this._messageBuffer);
this._messageBuffer = [];
}
}

private _sendMessages(messages: Array<Object>) { this._postMessageTarget.postMessage(messages); }
Expand Down
6 changes: 2 additions & 4 deletions modules/angular2/src/web_workers/worker/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ export function bootstrapWebWorker(
componentInjectableProviders: Array<Type | Provider | any[]> = null): Promise<ComponentRef> {
Parse5DomAdapter.makeCurrent();
var sink = new PostMessageBusSink({
postMessage: (message: any, transferrables?:[ArrayBuffer]) => {
console.log("Sending", message);
_postMessage(message, transferrables);
}
postMessage:
(message: any, transferrables?:[ArrayBuffer]) => { _postMessage(message, transferrables); }
});
var source = new PostMessageBusSource();
var bus = new PostMessageBus(sink, source);
Expand Down
1 change: 0 additions & 1 deletion modules/playground/src/web_workers/images/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ System.config({
System.import("playground/src/web_workers/images/background_index")
.then(
function(m) {
console.log("running main");
try {
m.main();
} catch (e) {
Expand Down
1 change: 0 additions & 1 deletion modules/playground/src/web_workers/kitchen_sink/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ System.config({
System.import("playground/src/web_workers/kitchen_sink/background_index")
.then(
function(m) {
console.log("running main");
try {
m.main();
} catch (e) {
Expand Down
1 change: 0 additions & 1 deletion modules/playground/src/web_workers/todo/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ System.config({
System.import("playground/src/web_workers/todo/background_index")
.then(
function(m) {
console.log("running main");
try {
m.main();
} catch (e) {
Expand Down

0 comments on commit 8485ef9

Please sign in to comment.