UNPKG

@hazae41/glacier

Version:

Yet another React data (re)fetching library

66 lines (63 loc) 1.62 kB
import { Err } from '@hazae41/result'; class Fail extends Err { error; time; cooldown; expiration; constructor(error, init = {}) { super(error); const { time = Date.now(), cooldown, expiration } = init; this.error = error; this.time = time; this.cooldown = cooldown; this.expiration = expiration; } static from(init) { const { error, time, cooldown, expiration } = init; return new Fail(error, { time, cooldown, expiration }); } isData() { return false; } isFail() { return true; } set(inner) { return this; } setErr(inner) { return new Fail(inner, this); } setInit(init) { return new Fail(this.inner, init); } async mapErr(mapper) { return new Fail(await mapper(this.getErr()), this); } mapErrSync(mapper) { return new Fail(mapper(this.getErr()), this); } /** * Transform Result<Promise<T>, E> into Promise<Result<T, E>> * @returns `await this.inner` if `Ok`, `this` if `Err` */ async await() { return this; } /** * Transform Result<T, Promise<E>> into Promise<Result<T, E>> * @returns `await this.inner` if `Err`, `this` if `Ok` */ async awaitErr() { return new Fail(await this.inner, this); } /** * Transform Result<Promise<T>, Promise<E>> into Promise<Result<T, E>> * @returns `await this.inner` */ async awaitAll() { return await this.awaitErr(); } } export { Fail }; //# sourceMappingURL=fail.mjs.map