Skip to content
Merged
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
6 changes: 2 additions & 4 deletions packages/playwright-core/src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { PipeTransport } from '@utils/pipeTransport';
import { createGuid } from '@utils/crypto';
import { isUnderTest } from '@utils/debug';
import { getPackageManagerExecCommand } from '@utils/env';
import { makeWaitForNextTask } from '@utils/task';
import { RecentLogsCollector } from '@utils/debugLogger';
import { removeFolders } from '@utils/fileUtils';
import { gracefullyCloseSet } from '@utils/processLauncher';
Expand Down Expand Up @@ -479,7 +478,6 @@ class AndroidBrowser extends EventEmitter {
readonly device: AndroidDevice;
private _socket: SocketBackend;
private _receiver: stream.Writable;
private _waitForNextTask = makeWaitForNextTask();
onmessage?: (message: any) => void;
onclose?: () => void;

Expand All @@ -489,14 +487,14 @@ class AndroidBrowser extends EventEmitter {
this.device = device;
this._socket = socket;
this._socket.on('close', () => {
this._waitForNextTask(() => {
setImmediate(() => {
if (this.onclose)
this.onclose();
});
});
this._receiver = new wsReceiver() as stream.Writable;
this._receiver.on('message', message => {
this._waitForNextTask(() => {
setImmediate(() => {
if (this.onmessage)
this.onmessage(JSON.parse(message));
});
Expand Down
3 changes: 1 addition & 2 deletions packages/playwright-core/src/server/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { LongStandingScope } from '@isomorphic/manualPromise';
import { asLocator } from '@isomorphic/locatorGenerators';
import { assert } from '@isomorphic/assert';
import { constructURLBasedOnBaseURL } from '@isomorphic/urlMatch';
import { makeWaitForNextTask } from '@utils/task';
import { createGuid } from '@utils/crypto';
import { BrowserContext } from './browserContext';
import * as dom from './dom';
Expand Down Expand Up @@ -199,7 +198,7 @@ export class FrameManager {
await progress.race(this._page.delegate.inputActionEpilogue());
await barrier.waitFor(progress);
// Resolve in the next task, after all waitForNavigations.
await new Promise<void>(makeWaitForNextTask());
await new Promise<void>(f => setImmediate(f));
return result;
} finally {
this._signalBarriers.delete(barrier);
Expand Down
6 changes: 2 additions & 4 deletions packages/playwright-core/src/server/pipeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
*/

import { debugLogger } from '@utils/debugLogger';
import { makeWaitForNextTask } from '@utils/task';

import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from './transport';

export class PipeTransport implements ConnectionTransport {
private _pipeRead: NodeJS.ReadableStream;
private _pipeWrite: NodeJS.WritableStream;
private _pendingBuffers: Buffer[] = [];
private _waitForNextTask = makeWaitForNextTask();
private _closed = false;
private _onclose?: (reason?: string) => void;

Expand Down Expand Up @@ -73,7 +71,7 @@ export class PipeTransport implements ConnectionTransport {
}
this._pendingBuffers.push(buffer.slice(0, end));
const message = Buffer.concat(this._pendingBuffers).toString();
this._waitForNextTask(() => {
setImmediate(() => {
if (this.onmessage)
this.onmessage.call(null, JSON.parse(message));
});
Expand All @@ -82,7 +80,7 @@ export class PipeTransport implements ConnectionTransport {
end = buffer.indexOf('\0', start);
while (end !== -1) {
const message = buffer.toString(undefined, start, end);
this._waitForNextTask(() => {
setImmediate(() => {
if (this.onmessage)
this.onmessage.call(null, JSON.parse(message));
});
Expand Down
3 changes: 1 addition & 2 deletions packages/playwright-core/src/server/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import ws from 'ws';
import { flattenAggregateError, happyEyeballsOptions } from '@utils/network';
import { makeWaitForNextTask } from '@utils/task';
import type { WebSocket } from 'ws';
import type { Progress } from './progress';
import type { HeadersArray } from './types';
Expand Down Expand Up @@ -153,7 +152,7 @@ export class WebSocketTransport implements ConnectionTransport {
// In Web, all IO callbacks (e.g. WebSocket callbacks)
// are dispatched into separate tasks, so there's no need
// to do anything extra.
const messageWrap: (cb: () => void) => void = makeWaitForNextTask();
const messageWrap: (cb: () => void) => void = setImmediate;

this._ws.addEventListener('message', event => {
messageWrap(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export * from './socksProxy';
export * from './spawnAsync';
export * from './stackTrace';
export * from './stringWidth';
export * from './task';
export * from './wsServer';
export * from './zipFile';
export * from './zones';
Expand Down
4 changes: 1 addition & 3 deletions packages/utils/pipeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { makeWaitForNextTask } from './task';

interface WritableStream {
write(data: Buffer): void;
Expand All @@ -32,7 +31,6 @@ interface ClosableStream {
export class PipeTransport {
private _pipeWrite: WritableStream;
private _data = Buffer.from([]);
private _waitForNextTask = makeWaitForNextTask();
private _closed = false;
private _bytesLeft = 0;

Expand Down Expand Up @@ -95,7 +93,7 @@ export class PipeTransport {
const message = this._data.slice(0, this._bytesLeft);
this._data = this._data.slice(this._bytesLeft);
this._bytesLeft = 0;
this._waitForNextTask(() => {
setImmediate(() => {
if (this.onmessage)
this.onmessage(message.toString('utf-8'));
});
Expand Down
55 changes: 0 additions & 55 deletions packages/utils/task.ts

This file was deleted.

Loading