Skip to content

Commit

Permalink
Nitpick
Browse files Browse the repository at this point in the history
  • Loading branch information
rojvv committed May 8, 2024
1 parent a1969fb commit d378c3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
23 changes: 14 additions & 9 deletions client_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,16 @@ export class ClientManager {
throw new InputError("getUpdates is not allowed when a webhook is set.");
}

if (this.#polls.has(client)) {
const controller = this.#getUpdatesControllers.get(client);
if (controller) {
controller.abort();
}
// just in case
this.#polls.delete(client);
this.#updateResolvers.delete(client);
if (this.#polls.has(client)) {
const controller = this.#getUpdatesControllers.get(client);
if (controller) {
controller.abort();
}
this.#getUpdatesControllers.delete(client);
// just in case
this.#polls.delete(client);
this.#updateResolvers.get(client)?.();
this.#updateResolvers.delete(client);
}
this.#polls.add(client);
let controller: AbortController | null = null;
Expand Down Expand Up @@ -280,7 +282,10 @@ export class ClientManager {
if (timeout != null) {
clearTimeout(timeout);
}
if (controller != null) {
if (
controller != null &&
this.#getUpdatesControllers.get(client) == controller
) {
this.#getUpdatesControllers.delete(client);
}
}
Expand Down
8 changes: 5 additions & 3 deletions worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { existsSync } from "std/fs/mod.ts";

import { InputError } from "mtkruto/0_errors.ts";
import { setLogVerbosity } from "mtkruto/1_utilities.ts";
import { functions, setLoggingProvider, types, Update } from "mtkruto/mod.ts";
import { functions, setLoggingProvider, types } from "mtkruto/mod.ts";

import { serialize } from "./tl_json.ts";
import { deserialize } from "./tl_json.ts";
Expand Down Expand Up @@ -201,7 +201,10 @@ async function stats(): Promise<WorkerStats> {
};
}

async function getUpdates(id: string, timeout: number): Promise<Parameters<typeof Response["json"]>> {
async function getUpdates(
id: string,
timeout: number,
): Promise<Parameters<typeof Response["json"]>> {
if (timeout < 0) {
throw new InputError(`Invalid timeout: ${timeout}`);
}
Expand Down Expand Up @@ -237,4 +240,3 @@ async function dropPendingUpdates(
await clientManager.dropPendingUpdates(id);
return [null];
}

0 comments on commit d378c3c

Please sign in to comment.