diff --git a/client_manager.ts b/client_manager.ts index 6dfaae7..a8bbc89 100644 --- a/client_manager.ts +++ b/client_manager.ts @@ -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; @@ -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); } } diff --git a/worker.ts b/worker.ts index 60eccdd..5c98aca 100644 --- a/worker.ts +++ b/worker.ts @@ -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"; @@ -201,7 +201,10 @@ async function stats(): Promise { }; } -async function getUpdates(id: string, timeout: number): Promise> { +async function getUpdates( + id: string, + timeout: number, +): Promise> { if (timeout < 0) { throw new InputError(`Invalid timeout: ${timeout}`); } @@ -237,4 +240,3 @@ async function dropPendingUpdates( await clientManager.dropPendingUpdates(id); return [null]; } - \ No newline at end of file