From afecac3e3cd8b851c8a2df90b9556ea6f01a54a2 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 16 Nov 2021 16:14:13 +0530 Subject: [PATCH] Convert timeout.js to ts --- src/platform/web/dom/request/fetch.js | 2 +- src/utils/{timeout.js => timeout.ts} | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) rename src/utils/{timeout.js => timeout.ts} (88%) diff --git a/src/platform/web/dom/request/fetch.js b/src/platform/web/dom/request/fetch.js index 66f1a148..adf833ef 100644 --- a/src/platform/web/dom/request/fetch.js +++ b/src/platform/web/dom/request/fetch.js @@ -19,7 +19,7 @@ import { AbortError, ConnectionError } from "../../../../matrix/error.js"; -import {abortOnTimeout} from "../../../../utils/timeout.js"; +import {abortOnTimeout} from "../../../../utils/timeout"; import {addCacheBuster} from "./common.js"; import {xhrRequest} from "./xhr.js"; diff --git a/src/utils/timeout.js b/src/utils/timeout.ts similarity index 88% rename from src/utils/timeout.js rename to src/utils/timeout.ts index 6bfc0d7e..96efc10d 100644 --- a/src/utils/timeout.js +++ b/src/utils/timeout.ts @@ -16,9 +16,13 @@ limitations under the License. */ import {ConnectionError} from "../matrix/error.js"; +import type {Timeout} from "../platform/web/dom/Clock.js" +type TimeoutCreator = (ms: number) => Timeout; +// ts-todo: export type RequestResult from fetch.js? we'll need to wait until it's typescript though. +type Abortable = { abort(): void; [key: string]: any }; -export function abortOnTimeout(createTimeout, timeoutAmount, requestResult, responsePromise) { +export function abortOnTimeout(createTimeout: TimeoutCreator, timeoutAmount: number, requestResult: Abortable, responsePromise: Promise) { const timeout = createTimeout(timeoutAmount); // abort request if timeout finishes first let timedOut = false;