Skip to main content

@8v/retry@0.1.4

latest
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
23%
Published
a month ago (0.1.4)

Github Repo

Usage

#!/usr/bin/env bun

import retry from "./mod.js";

let retryed = 0;

const test = retry(
  () => {
    if (++retryed < 3) {
      throw new Error("test");
    }
  },
);

await test();

Code

mod.js

import sleep from "@3-/sleep";

export default (func, times = 3) => async (...args) => {
  let n = 0;
  while (1) {
    try {
      return await func(...args);
    } catch (e) {
      if (times < ++n) {
        throw e;
      }
      console.error(e, args);
      await sleep(1e3);
    }
  }
};

About

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Add Package

deno add jsr:@8v/retry

Import symbol

import * as retry from "@8v/retry";

---- OR ----

Import directly with a jsr specifier

import * as retry from "jsr:@8v/retry";

Add Package

npx jsr add @8v/retry

Import symbol

import * as retry from "@8v/retry";

Add Package

yarn dlx jsr add @8v/retry

Import symbol

import * as retry from "@8v/retry";

Add Package

pnpm dlx jsr add @8v/retry

Import symbol

import * as retry from "@8v/retry";

Add Package

bunx jsr add @8v/retry

Import symbol

import * as retry from "@8v/retry";