Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Copy Markdown
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
Copy Markdown
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
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 = [];
Copy link
Copy Markdown
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
Copy Markdown
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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