Why does this take so long?
kayvanbree opened this issue · 2 comments
I am opening a new window and as soon as the subscription fires I want to send a message. My heartbeat config is at 100, but receiving the OPEN_PANEL_EVENT message takes about 6 seconds every time. Shouldn't this be faster (~2x100ms)? Does this subscription fire at the same rate as the heartbeat? I couldn't really figure that out reading the source code yet.
newWindow.created.subscribe(
() => {
console.log('Its here!');
},
(error) => {
console.log('Something went wrong opening ' + panel.name + ' in a new window. Please try again.');
},
() => {
console.log('Try sending a message');
this.sendMessage(newWindow.windowId, DockerService.OPEN_PANEL_EVENT, panel.name);
}
);
Oh, why is the third parameter of subscribe firing, not the first? (just read the comments of the subscribe method. I get it now)
I'd have to test your code sample to be certain, but I assume it's due to the first window not having performed a scan for new windows yet (https://github.com/Nolanus/ngx-multi-window#new-windows).
During this scan all localStorage keys will be received and filtered for window ids. As the first window has not scanned for new windows, it does not read the new windows messages
array/outbox. Thus it does not receive the answer for the PING message that was send by the first message when calling MultiWindowService.newWindow()
That makes sense, thanks! I'll find a way that doesn't need local storage polling for this then.