Repository: discordjs/discord.js
File: packages/ws/src/ws/WebSocketShard.ts (TypeScript)

Code before:
	// Indicates whether the shard has already resolved its original connect() call
	private initialConnectResolved = false;

	// Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET)
	private failedToConnectDueToNetworkError = false;

	private readonly sendQueue = new AsyncQueue();

	private readonly timeoutAbortControllers = new Collection<WebSocketShardEvents, AbortController>();

	private readonly strategy: IContextFetchingStrategy;

	public readonly id: number;

	#status: WebSocketShardStatus = WebSocketShardStatus.Idle;

	private identifyCompressionEnabled = false;

	/**
	 * @privateRemarks
	 *
	 * This is needed because `this.strategy.options.compression` is not an actual reflection of the compression method
	 * used, but rather the compression method that the user wants to use. This is because the libraries could just be missing.
	 */
	private get transportCompressionEnabled() {
		return this.strategy.options.compression !== null && (Boolean(this.nativeInflate) || Boolean(this.zLibSyncInflate));
	}

	public get status(): WebSocketShardStatus {
		return this.#status;
	}

	public constructor(strategy: IContextFetchingStrategy, id: number) {
		super();
		this.strategy = strategy;
		this.id = id;
	}

	public async connect() {
		const controller = new AbortController();
		let promise;

		if (!this.initialConnectResolved) {
			// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn
			promise = Promise.race([
				once(this, WebSocketShardEvents.Ready, { signal: controller.signal }),
				once(this, WebSocketShardEvents.Resumed, { signal: controller.signal }),
			]);
		}

		void this.internalConnect();

Review comment (suggestion):
Single `Boolean` call:
```suggestion
		return this.strategy.options.compression !== null && Boolean(this.nativeInflate || this.zLibSyncInflate);
```

Alternatively:
```suggestion
		return this.strategy.options.compression !== null && (this.nativeInflate ?? this.zLibSyncInflate) !== null;
```

Code after:
	// Indicates whether the shard has already resolved its original connect() call
	private initialConnectResolved = false;

	// Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET)
	private failedToConnectDueToNetworkError = false;

	private readonly sendQueue = new AsyncQueue();

	private readonly timeoutAbortControllers = new Collection<WebSocketShardEvents, AbortController>();

	private readonly strategy: IContextFetchingStrategy;

	public readonly id: number;

	#status: WebSocketShardStatus = WebSocketShardStatus.Idle;

	private identifyCompressionEnabled = false;

	/**
	 * @privateRemarks
	 *
	 * This is needed because `this.strategy.options.compression` is not an actual reflection of the compression method
	 * used, but rather the compression method that the user wants to use. This is because the libraries could just be missing.
	 */
	private get transportCompressionEnabled() {
		return this.strategy.options.compression !== null && (this.nativeInflate ?? this.zLibSyncInflate) !== null;
	}

	public get status(): WebSocketShardStatus {
		return this.#status;
	}

	public constructor(strategy: IContextFetchingStrategy, id: number) {
		super();
		this.strategy = strategy;
		this.id = id;
	}

	public async connect() {
		const controller = new AbortController();
		let promise;

		if (!this.initialConnectResolved) {
			// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn
			promise = Promise.race([
				once(this, WebSocketShardEvents.Ready, { signal: controller.signal }),
				once(this, WebSocketShardEvents.Resumed, { signal: controller.signal }),
			]);
		}

		void this.internalConnect();