Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasbadadare committed Jan 15, 2025
1 parent ffb9422 commit d0bc650
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lazer/sdk/js/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function main() {
);

// Monitor for all connections being down
client.onAllConnectionsDown().then(() => {
void client.onAllConnectionsDown().then(() => {
// Handle complete connection failure.
// The connections will keep attempting to reconnect with expo backoff.
// To shutdown the client completely, call shutdown().
Expand Down Expand Up @@ -82,7 +82,7 @@ async function main() {
client.shutdown();
}

main().catch((error) => {
await main().catch((error: unknown) => {
console.error("Unhandled error:", error);
process.exit(1);
throw error;
});
4 changes: 2 additions & 2 deletions lazer/sdk/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type Response,
SOLANA_FORMAT_MAGIC_BE,
} from "./protocol.js";
import { WebSocketPool } from "./socket/web-socket-pool.js";
import { WebSocketPool } from "./socket/websocket-pool.js";

export type BinaryResponse = {
subscriptionId: number;
Expand All @@ -36,7 +36,7 @@ export class PythLazerClient {
* Creates a new PythLazerClient instance.
* @param urls - List of WebSocket URLs of the Pyth Lazer service
* @param token - The access token for authentication
* @param numConnections - The number of parallel WebSocket connections to establish (default: 3). A higher number gives a more reliable stream.
* @param numConnections - The number of parallel WebSocket connections to establish (default: 3). A higher number gives a more reliable stream. The connections will round-robin across the provided URLs.
* @param logger - Optional logger to get socket level logs. Compatible with most loggers such as the built-in console and `bunyan`.
*/
static async create(
Expand Down
7 changes: 4 additions & 3 deletions lazer/sdk/js/src/socket/resilient-websocket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ClientRequestArgs } from "node:http";

import WebSocket, { type ClientOptions, type ErrorEvent } from "isomorphic-ws";
import type { Logger } from "ts-log";

Expand All @@ -16,7 +17,7 @@ export class ResilientWebSocket {
private connectionPromise: Promise<void> | undefined;
private resolveConnection: (() => void) | undefined;
private rejectConnection: ((error: Error) => void) | undefined;
private _isReconnecting: boolean = false;
private _isReconnecting = false;

get isReconnecting(): boolean {
return this._isReconnecting;
Expand Down Expand Up @@ -72,7 +73,7 @@ export class ResilientWebSocket {
if (this.connectionPromise) {
return this.connectionPromise;
}
return Promise.resolve();
return;
}

this.logger?.info(`Creating Web Socket client`);
Expand All @@ -87,7 +88,7 @@ export class ResilientWebSocket {
const timeoutId = setTimeout(() => {
if (this.rejectConnection) {
this.rejectConnection(
new Error(`Connection timeout after ${CONNECTION_TIMEOUT}ms`)
new Error(`Connection timeout after ${String(CONNECTION_TIMEOUT)}ms`)
);
}
}, CONNECTION_TIMEOUT);
Expand Down
12 changes: 7 additions & 5 deletions lazer/sdk/js/src/socket/websocket-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import TTLCache from "@isaacs/ttlcache";
import WebSocket from "isomorphic-ws";
import { dummyLogger, type Logger } from "ts-log";

import { ResilientWebSocket } from "./resilient-web-socket.js";
import { ResilientWebSocket } from "./resilient-websocket.js";
import type { Request, Response } from "../protocol.js";

const DEFAULT_NUM_CONNECTIONS = 3;
Expand All @@ -13,7 +13,7 @@ export class WebSocketPool {
private subscriptions: Map<number, Request>; // id -> subscription Request
private messageListeners: ((event: WebSocket.Data) => void)[];
private allConnectionsDownListeners: (() => void)[];
private wasAllDown: boolean = true;
private wasAllDown = true;

private constructor(private readonly logger: Logger = dummyLogger) {
this.rwsPool = [];
Expand All @@ -23,7 +23,9 @@ export class WebSocketPool {
this.allConnectionsDownListeners = [];

// Start monitoring connection states
setInterval(() => this.checkConnectionStates(), 100);
setInterval(() => {
this.checkConnectionStates();
}, 100);
}

/**
Expand Down Expand Up @@ -179,8 +181,8 @@ export class WebSocketPool {
}

/**
* Monitors if all websocket connections are currently down or in reconnecting state
* Returns a promise that resolves when all connections are down
* Monitors if all websocket connections are currently down or in reconnecting state.
* Returns a promise that resolves when all connections are down.
*/
onAllConnectionsDown(): Promise<void> {
return new Promise((resolve) => {
Expand Down

0 comments on commit d0bc650

Please sign in to comment.