@abacus-network/utils
Advanced tools
Comparing version 0.2.1-alpha5 to 0.2.1-alpha6
@@ -12,2 +12,4 @@ import { ethers } from 'ethers'; | ||
export declare function domainHash(domain: number): string; | ||
export declare function sleep(ms: number): Promise<void>; | ||
export declare function retryAsync<T>(runner: () => T, attempts?: number, delay?: number): Promise<T>; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.domainHash = exports.destinationAndNonce = exports.messageHash = exports.formatMessage = exports.formatCallData = exports.bytes32ToAddress = exports.addressToBytes32 = exports.stringToBytes32 = exports.getHexStringByteLength = void 0; | ||
exports.retryAsync = exports.sleep = exports.domainHash = exports.destinationAndNonce = exports.messageHash = exports.formatMessage = exports.formatCallData = exports.bytes32ToAddress = exports.addressToBytes32 = exports.stringToBytes32 = exports.getHexStringByteLength = void 0; | ||
const chai_1 = require("chai"); | ||
@@ -65,2 +74,24 @@ const ethers_1 = require("ethers"); | ||
exports.domainHash = domainHash; | ||
function sleep(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
exports.sleep = sleep; | ||
// Retries an async function when it raises an exeption | ||
// if all the tries fail it raises the last thrown exeption | ||
function retryAsync(runner, attempts = 3, delay = 500) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let saveError; | ||
for (let i = 0; i < attempts; i++) { | ||
try { | ||
return runner(); | ||
} | ||
catch (error) { | ||
saveError = error; | ||
yield sleep(delay * (i + 1)); | ||
} | ||
} | ||
throw saveError; | ||
}); | ||
} | ||
exports.retryAsync = retryAsync; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@abacus-network/utils", | ||
"description": "General utilities for the Abacus network", | ||
"version": "0.2.1-alpha5", | ||
"version": "0.2.1-alpha6", | ||
"dependencies": { | ||
@@ -6,0 +6,0 @@ "chai": "^4.3.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21013
278