mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Convert ExponentialRetryDelay.js to ts
This commit is contained in:
parent
3a24019d96
commit
e1a823400a
@ -21,7 +21,7 @@ import {AbortableOperation} from "../utils/AbortableOperation";
|
||||
import {ObservableValue} from "../observable/ObservableValue";
|
||||
import {HomeServerApi} from "./net/HomeServerApi.js";
|
||||
import {Reconnector, ConnectionStatus} from "./net/Reconnector.js";
|
||||
import {ExponentialRetryDelay} from "./net/ExponentialRetryDelay.js";
|
||||
import {ExponentialRetryDelay} from "./net/ExponentialRetryDelay";
|
||||
import {MediaRepository} from "./net/MediaRepository.js";
|
||||
import {RequestScheduler} from "./net/RequestScheduler.js";
|
||||
import {Sync, SyncStatus} from "./Sync.js";
|
||||
|
@ -15,18 +15,28 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import {AbortError} from "../../utils/error";
|
||||
import type {Timeout} from "../../platform/web/dom/Clock.js";
|
||||
|
||||
type TimeoutCreator = (ms: number) => Timeout;
|
||||
|
||||
const enum Default { start = 2000 }
|
||||
|
||||
export class ExponentialRetryDelay {
|
||||
constructor(createTimeout) {
|
||||
private readonly _start: number = Default.start;
|
||||
private _current: number = Default.start;
|
||||
private readonly _createTimeout: TimeoutCreator;
|
||||
private readonly _max: number;
|
||||
private _timeout?: Timeout;
|
||||
|
||||
constructor(createTimeout: TimeoutCreator) {
|
||||
const start = 2000;
|
||||
this._start = start;
|
||||
this._current = start;
|
||||
this._createTimeout = createTimeout;
|
||||
this._max = 60 * 5 * 1000; //5 min
|
||||
this._timeout = null;
|
||||
}
|
||||
|
||||
async waitForRetry() {
|
||||
async waitForRetry(): Promise<void> {
|
||||
this._timeout = this._createTimeout(this._current);
|
||||
try {
|
||||
await this._timeout.elapsed();
|
||||
@ -39,22 +49,22 @@ export class ExponentialRetryDelay {
|
||||
throw err;
|
||||
}
|
||||
} finally {
|
||||
this._timeout = null;
|
||||
this._timeout = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
abort() {
|
||||
abort(): void {
|
||||
if (this._timeout) {
|
||||
this._timeout.abort();
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
reset(): void {
|
||||
this._current = this._start;
|
||||
this.abort();
|
||||
}
|
||||
|
||||
get nextValue() {
|
||||
get nextValue(): number {
|
||||
return this._current;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {encodeQueryParams, encodeBody} from "./common.js";
|
||||
import {encodeQueryParams, encodeBody} from "./common";
|
||||
import {HomeServerRequest} from "./HomeServerRequest.js";
|
||||
|
||||
const CS_R0_PREFIX = "/_matrix/client/r0";
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {encodeQueryParams} from "./common.js";
|
||||
import {encodeQueryParams} from "./common";
|
||||
import {decryptAttachment} from "../e2ee/attachment.js";
|
||||
|
||||
export class MediaRepository {
|
||||
|
@ -120,7 +120,7 @@ export class Reconnector {
|
||||
|
||||
|
||||
import {Clock as MockClock} from "../../mocks/Clock.js";
|
||||
import {ExponentialRetryDelay} from "./ExponentialRetryDelay.js";
|
||||
import {ExponentialRetryDelay} from "./ExponentialRetryDelay";
|
||||
import {ConnectionError} from "../error.js"
|
||||
|
||||
export function tests() {
|
||||
|
@ -18,7 +18,7 @@ limitations under the License.
|
||||
import {AbortError} from "../../utils/error";
|
||||
import {HomeServerError} from "../error.js";
|
||||
import {HomeServerApi} from "./HomeServerApi.js";
|
||||
import {ExponentialRetryDelay} from "./ExponentialRetryDelay.js";
|
||||
import {ExponentialRetryDelay} from "./ExponentialRetryDelay";
|
||||
|
||||
class Request {
|
||||
constructor(methodName, args) {
|
||||
|
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// todo: this file should be called something else?
|
||||
|
||||
import type {RequestResult} from "../web/dom/request/fetch.js";
|
||||
import type {IEncodedBody} from "../../matrix/net/common";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user