fix(webkit): make sure each message is dispatch in separate task (#212)
This commit is contained in:
parent
357e175964
commit
ce21019c7d
|
|
@ -36,6 +36,7 @@ export class Connection extends EventEmitter {
|
||||||
private readonly _sessions = new Map<string, TargetSession>();
|
private readonly _sessions = new Map<string, TargetSession>();
|
||||||
private _incomingMessageQueue: string[] = [];
|
private _incomingMessageQueue: string[] = [];
|
||||||
private _dispatchTimerId?: NodeJS.Timer;
|
private _dispatchTimerId?: NodeJS.Timer;
|
||||||
|
private _sameDispatchTask: boolean = false;
|
||||||
|
|
||||||
_closed = false;
|
_closed = false;
|
||||||
|
|
||||||
|
|
@ -71,10 +72,15 @@ export class Connection extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onMessage(message: string) {
|
private _onMessage(message: string) {
|
||||||
if (this._incomingMessageQueue.length || this._delay)
|
if (this._sameDispatchTask || this._incomingMessageQueue.length || this._delay)
|
||||||
this._enqueueMessage(message);
|
this._enqueueMessage(message);
|
||||||
else
|
else {
|
||||||
|
this._sameDispatchTask = true;
|
||||||
|
// This is for the case when several messages come in a batch and read
|
||||||
|
// in a loop by transport ending up in the same task.
|
||||||
|
Promise.resolve().then(() => this._sameDispatchTask = false);
|
||||||
this._dispatchMessage(message);
|
this._dispatchMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _enqueueMessage(message: string) {
|
private _enqueueMessage(message: string) {
|
||||||
|
|
@ -100,6 +106,8 @@ export class Connection extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _dispatchOneMessageFromQueue() {
|
private _dispatchOneMessageFromQueue() {
|
||||||
|
if (this._closed)
|
||||||
|
return;
|
||||||
const message = this._incomingMessageQueue.shift();
|
const message = this._incomingMessageQueue.shift();
|
||||||
try {
|
try {
|
||||||
this._dispatchMessage(message);
|
this._dispatchMessage(message);
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ export class Target {
|
||||||
await (this._page._delegate as FrameManager)._initializeSession(session).catch(e => {
|
await (this._page._delegate as FrameManager)._initializeSession(session).catch(e => {
|
||||||
// Swallow initialization errors due to newer target swap in,
|
// Swallow initialization errors due to newer target swap in,
|
||||||
// since we will reinitialize again.
|
// since we will reinitialize again.
|
||||||
if (!isSwappedOutError(e))
|
if (this._page)
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue