Skip to content

Commit

Permalink
delay util
Browse files Browse the repository at this point in the history
  • Loading branch information
John-peterson-coinbase committed May 16, 2024
1 parent d538a1f commit 441d808
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/coinbase/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Coinbase } from "./coinbase";
import { Transfer as TransferModel } from "../client/api";
import { ethers } from "ethers";
import { InternalError, InvalidUnsignedPayload } from "./errors";
import { delay } from "./utils";

/**
* The Transfer API client types.
Expand Down Expand Up @@ -218,7 +219,7 @@ export class Transfer {
if (status === TransferStatus.COMPLETE || status === TransferStatus.FAILED) {
return this;
}
await new Promise(resolve => setTimeout(resolve, intervalSeconds * 1000));
await delay(intervalSeconds);
}
throw new Error("Transfer timed out");
}
Expand Down
10 changes: 10 additions & 0 deletions src/coinbase/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ export const registerAxiosInterceptors = (
export const convertStringToHex = (key: Uint8Array): string => {
return Buffer.from(key).toString("hex");
};

/**
* Delays the execution of the function by the specified number of seconds.
*
* @param seconds - The number of seconds to delay the execution.
* @returns A promise that resolves after the specified number of seconds.
*/
export async function delay(seconds: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}

0 comments on commit 441d808

Please sign in to comment.