forked from mystiq/hydrogen-web
Convert timeout.js to ts
This commit is contained in:
parent
8a169d5ddc
commit
afecac3e3c
2 changed files with 6 additions and 2 deletions
|
@ -19,7 +19,7 @@ import {
|
||||||
AbortError,
|
AbortError,
|
||||||
ConnectionError
|
ConnectionError
|
||||||
} from "../../../../matrix/error.js";
|
} from "../../../../matrix/error.js";
|
||||||
import {abortOnTimeout} from "../../../../utils/timeout.js";
|
import {abortOnTimeout} from "../../../../utils/timeout";
|
||||||
import {addCacheBuster} from "./common.js";
|
import {addCacheBuster} from "./common.js";
|
||||||
import {xhrRequest} from "./xhr.js";
|
import {xhrRequest} from "./xhr.js";
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,13 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ConnectionError} from "../matrix/error.js";
|
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<Response>) {
|
||||||
const timeout = createTimeout(timeoutAmount);
|
const timeout = createTimeout(timeoutAmount);
|
||||||
// abort request if timeout finishes first
|
// abort request if timeout finishes first
|
||||||
let timedOut = false;
|
let timedOut = false;
|
Loading…
Add table
Reference in a new issue