Skip to content

Commit d0bc650

Browse files
committed
fix: lint
1 parent ffb9422 commit d0bc650

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

lazer/sdk/js/examples/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function main() {
1515
);
1616

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

85-
main().catch((error) => {
85+
await main().catch((error: unknown) => {
8686
console.error("Unhandled error:", error);
87-
process.exit(1);
87+
throw error;
8888
});

lazer/sdk/js/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type Response,
1111
SOLANA_FORMAT_MAGIC_BE,
1212
} from "./protocol.js";
13-
import { WebSocketPool } from "./socket/web-socket-pool.js";
13+
import { WebSocketPool } from "./socket/websocket-pool.js";
1414

1515
export type BinaryResponse = {
1616
subscriptionId: number;
@@ -36,7 +36,7 @@ export class PythLazerClient {
3636
* Creates a new PythLazerClient instance.
3737
* @param urls - List of WebSocket URLs of the Pyth Lazer service
3838
* @param token - The access token for authentication
39-
* @param numConnections - The number of parallel WebSocket connections to establish (default: 3). A higher number gives a more reliable stream.
39+
* @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.
4040
* @param logger - Optional logger to get socket level logs. Compatible with most loggers such as the built-in console and `bunyan`.
4141
*/
4242
static async create(

lazer/sdk/js/src/socket/resilient-websocket.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ClientRequestArgs } from "node:http";
2+
23
import WebSocket, { type ClientOptions, type ErrorEvent } from "isomorphic-ws";
34
import type { Logger } from "ts-log";
45

@@ -16,7 +17,7 @@ export class ResilientWebSocket {
1617
private connectionPromise: Promise<void> | undefined;
1718
private resolveConnection: (() => void) | undefined;
1819
private rejectConnection: ((error: Error) => void) | undefined;
19-
private _isReconnecting: boolean = false;
20+
private _isReconnecting = false;
2021

2122
get isReconnecting(): boolean {
2223
return this._isReconnecting;
@@ -72,7 +73,7 @@ export class ResilientWebSocket {
7273
if (this.connectionPromise) {
7374
return this.connectionPromise;
7475
}
75-
return Promise.resolve();
76+
return;
7677
}
7778

7879
this.logger?.info(`Creating Web Socket client`);
@@ -87,7 +88,7 @@ export class ResilientWebSocket {
8788
const timeoutId = setTimeout(() => {
8889
if (this.rejectConnection) {
8990
this.rejectConnection(
90-
new Error(`Connection timeout after ${CONNECTION_TIMEOUT}ms`)
91+
new Error(`Connection timeout after ${String(CONNECTION_TIMEOUT)}ms`)
9192
);
9293
}
9394
}, CONNECTION_TIMEOUT);

lazer/sdk/js/src/socket/websocket-pool.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import TTLCache from "@isaacs/ttlcache";
22
import WebSocket from "isomorphic-ws";
33
import { dummyLogger, type Logger } from "ts-log";
44

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

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

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

2525
// Start monitoring connection states
26-
setInterval(() => this.checkConnectionStates(), 100);
26+
setInterval(() => {
27+
this.checkConnectionStates();
28+
}, 100);
2729
}
2830

2931
/**
@@ -179,8 +181,8 @@ export class WebSocketPool {
179181
}
180182

181183
/**
182-
* Monitors if all websocket connections are currently down or in reconnecting state
183-
* Returns a promise that resolves when all connections are down
184+
* Monitors if all websocket connections are currently down or in reconnecting state.
185+
* Returns a promise that resolves when all connections are down.
184186
*/
185187
onAllConnectionsDown(): Promise<void> {
186188
return new Promise((resolve) => {

0 commit comments

Comments
 (0)