Skip to content

Commit

Permalink
changes from PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlei committed Jul 31, 2023
1 parent 42d61fa commit dbfaec0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testnet-faucet",
"version": "1.0.0",
"version": "2.0.0",
"description": "",
"main": "dist/src/index.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { populateTicketQueue } from "./ticket-queue";
let { client, clientCreatedDate: _clientCreatedDate } = createClient();
let connecting = false;

// connect the client and populate the ticket queue immediately after creation
getConnectedClient();

client.on("error", (errorCode, errorMessage) => {
console.log("Client error: " + errorCode + ": " + errorMessage);
});
Expand All @@ -14,8 +17,6 @@ client.on("connected", () => {
});

client.on("disconnected", (code) => {
// code - [close code](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) sent by the server
// will be 1000 if this was normal closure
console.log("Client disconnected, code:", code);
});

Expand Down Expand Up @@ -55,6 +56,9 @@ export async function getConnectedClient(): Promise<Client> {
await client.connect();
await populateTicketQueue(client);
}
} catch (error) {
console.error(`Failed to get connected client. Error: ${error.message}`);
throw error;
} finally {
connecting = false;
}
Expand Down Expand Up @@ -91,5 +95,6 @@ export async function resetClient(reqId: string) {
client = newClientData.client;
_clientCreatedDate = newClientData.clientCreatedDate;
await getConnectedClient();
await populateTicketQueue(client); // Populate the ticket queue after reconnection
console.log(`${reqId}| client reconnected.`);
}
1 change: 0 additions & 1 deletion src/ticket-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export async function getTicket(client: Client) {
if (ticketQueue.length === 0) {
console.log(`${rTracer.id()} | Waiting for tickets to be created.`);
await createTicketsPromise;
return ticketQueue.shift();
}

const ticket = ticketQueue.shift();
Expand Down

0 comments on commit dbfaec0

Please sign in to comment.