Skip to content

Commit

Permalink
chore(async): remove _exponentialBackoffWithJitter from public file (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
lino-levan committed Oct 25, 2023
1 parent 8993c21 commit a3ddd35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
13 changes: 13 additions & 0 deletions async/_util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

export function _exponentialBackoffWithJitter(
cap: number,
base: number,
attempt: number,
multiplier: number,
jitter: number,
) {
const exp = Math.min(cap, base * multiplier ** attempt);
return (1 - jitter * Math.random()) * exp;
}
12 changes: 1 addition & 11 deletions async/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This module is browser compatible.

import { assert } from "../assert/assert.ts";
import { _exponentialBackoffWithJitter } from "./_util.ts";

export class RetryError extends Error {
constructor(cause: unknown, attempts: number) {
Expand Down Expand Up @@ -116,14 +117,3 @@ export async function retry<T>(
attempt++;
}
}

export function _exponentialBackoffWithJitter(
cap: number,
base: number,
attempt: number,
multiplier: number,
jitter: number,
) {
const exp = Math.min(cap, base * multiplier ** attempt);
return (1 - jitter * Math.random()) * exp;
}
3 changes: 2 additions & 1 deletion async/retry_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { _exponentialBackoffWithJitter, retry, RetryError } from "./retry.ts";
import { retry, RetryError } from "./retry.ts";
import { _exponentialBackoffWithJitter } from "./_util.ts";
import { assertEquals, assertRejects } from "../assert/mod.ts";
import { FakeTime } from "../testing/time.ts";

Expand Down

0 comments on commit a3ddd35

Please sign in to comment.