fix(WebWorker): Don't send messages when the buffer is empty
Closes #4138
This commit is contained in:
parent
1de2d29f96
commit
8485ef9230
|
@ -46,8 +46,10 @@ abstract class GenericMessageBusSink implements MessageBusSink {
|
||||||
void attachToZone(NgZone zone) {
|
void attachToZone(NgZone zone) {
|
||||||
_zone = zone;
|
_zone = zone;
|
||||||
_zone.overrideOnEventDone(() {
|
_zone.overrideOnEventDone(() {
|
||||||
sendMessages(_messageBuffer);
|
if (_messageBuffer.length > 0) {
|
||||||
_messageBuffer.clear();
|
sendMessages(_messageBuffer);
|
||||||
|
_messageBuffer.clear();
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,10 @@ export class PostMessageBusSink implements MessageBusSink {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleOnEventDone() {
|
private _handleOnEventDone() {
|
||||||
// TODO: Send all buffered messages in one postMessage call
|
if (this._messageBuffer.length > 0) {
|
||||||
this._sendMessages(this._messageBuffer);
|
this._sendMessages(this._messageBuffer);
|
||||||
this._messageBuffer = [];
|
this._messageBuffer = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _sendMessages(messages: Array<Object>) { this._postMessageTarget.postMessage(messages); }
|
private _sendMessages(messages: Array<Object>) { this._postMessageTarget.postMessage(messages); }
|
||||||
|
|
|
@ -32,10 +32,8 @@ export function bootstrapWebWorker(
|
||||||
componentInjectableProviders: Array<Type | Provider | any[]> = null): Promise<ComponentRef> {
|
componentInjectableProviders: Array<Type | Provider | any[]> = null): Promise<ComponentRef> {
|
||||||
Parse5DomAdapter.makeCurrent();
|
Parse5DomAdapter.makeCurrent();
|
||||||
var sink = new PostMessageBusSink({
|
var sink = new PostMessageBusSink({
|
||||||
postMessage: (message: any, transferrables?:[ArrayBuffer]) => {
|
postMessage:
|
||||||
console.log("Sending", message);
|
(message: any, transferrables?:[ArrayBuffer]) => { _postMessage(message, transferrables); }
|
||||||
_postMessage(message, transferrables);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var source = new PostMessageBusSource();
|
var source = new PostMessageBusSource();
|
||||||
var bus = new PostMessageBus(sink, source);
|
var bus = new PostMessageBus(sink, source);
|
||||||
|
|
|
@ -10,7 +10,6 @@ System.config({
|
||||||
System.import("playground/src/web_workers/images/background_index")
|
System.import("playground/src/web_workers/images/background_index")
|
||||||
.then(
|
.then(
|
||||||
function(m) {
|
function(m) {
|
||||||
console.log("running main");
|
|
||||||
try {
|
try {
|
||||||
m.main();
|
m.main();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ System.config({
|
||||||
System.import("playground/src/web_workers/kitchen_sink/background_index")
|
System.import("playground/src/web_workers/kitchen_sink/background_index")
|
||||||
.then(
|
.then(
|
||||||
function(m) {
|
function(m) {
|
||||||
console.log("running main");
|
|
||||||
try {
|
try {
|
||||||
m.main();
|
m.main();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ System.config({
|
||||||
System.import("playground/src/web_workers/todo/background_index")
|
System.import("playground/src/web_workers/todo/background_index")
|
||||||
.then(
|
.then(
|
||||||
function(m) {
|
function(m) {
|
||||||
console.log("running main");
|
|
||||||
try {
|
try {
|
||||||
m.main();
|
m.main();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue