Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Text · 22 lines · 761 B · at 9ba9e6b

import { type Option, type Result } from "@tsus/runtime";export type HttpResponse = { status: number; body: string };export type NetworkError = { kind: "network"; message: string };export type Fetcher = (url: string) => Promise<Result<HttpResponse, NetworkError>>;export type RetryOptions = {  retries: number;  baseDelayMs: number;  sleep: (ms: number) => Promise<void>;};export type RetryError =  | { kind: "http"; status: number }  /** lastStatus: status of the final attempt if it was 5xx; None if it was a network error. */  | { kind: "exhausted"; attempts: number; lastStatus: Option<number> };export const retryFetch = async (fetcher: Fetcher, url: string, options: RetryOptions): Promise<Result<string, RetryError>> => {  // TODO};