Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(WebWorker): Don't send messages when the buffer is empty #4138

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check be in the sendMessages method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because sendMessages is called whenever the there are messages to send. It's overridden by the specific message bus implementations, so it doesn't make sense to call it with an empty array.

sendMessages(_messageBuffer);
_messageBuffer.clear();
}
}, false);
}

Expand Down
7 changes: 4 additions & 3 deletions modules/angular2/src/web_workers/shared/post_message_bus.ts
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 = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this._messageBuffer.clear() above, but not here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK JavaScript arrays don't have a clear method.

}
}

private _sendMessages(messages: Array<Object>) { this._postMessageTarget.postMessage(messages); }
Expand Down
1 change: 0 additions & 1 deletion modules/angular2/src/web_workers/worker/application.ts
Expand Up @@ -31,7 +31,6 @@ export function bootstrapWebWorker(
Promise<ApplicationRef> {
var sink = new PostMessageBusSink({
postMessage: (message: any, transferrables?:[ArrayBuffer]) => {
console.log("Sending", message);
_postMessage(message, transferrables);
}
});
Expand Down
1 change: 0 additions & 1 deletion modules/examples/src/web_workers/images/loader.js
Expand Up @@ -13,7 +13,6 @@ System.config({
System.import("examples/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/examples/src/web_workers/message_broker/loader.js
Expand Up @@ -9,7 +9,6 @@ $SCRIPTS$
System.import("examples/src/web_workers/message_broker/background_index")
.then(
function(m) {
console.log("running main");
try {
m.main();
} catch (e) {
Expand Down
1 change: 0 additions & 1 deletion modules/examples/src/web_workers/todo/loader.js
Expand Up @@ -11,7 +11,6 @@ System.config({
System.import("examples/src/web_workers/todo/background_index")
.then(
function(m) {
console.log("running main");
try {
m.main();
} catch (e) {
Expand Down