appolo-utils
Advanced tools
Comparing version 0.0.53 to 0.0.54
@@ -69,2 +69,15 @@ "use strict"; | ||
} | ||
static timeout(promise, timeout) { | ||
return Promises.promiseTimeout(promise, timeout); | ||
} | ||
static async retry(fn, retires = 1) { | ||
let [err, result] = await Promises.to(fn()); | ||
if (err == null) { | ||
return result; | ||
} | ||
if (retires <= 0) { | ||
throw err; | ||
} | ||
return Promises.retry(fn, --retires); | ||
} | ||
static promiseTimeout(promise, timeout) { | ||
@@ -71,0 +84,0 @@ return new Promise((resolve, reject) => { |
@@ -93,2 +93,20 @@ import {Deferred} from "./deferred"; | ||
public static timeout<T>(promise: Promise<T>, timeout: number): Promise<T> { | ||
return Promises.promiseTimeout(promise, timeout) | ||
} | ||
public static async retry<T>(fn: () => Promise<T>, retires: number = 1): Promise<T> { | ||
let [err, result] = await Promises.to(fn()); | ||
if (err == null) { | ||
return result | ||
} | ||
if (retires <= 0) { | ||
throw err; | ||
} | ||
return Promises.retry(fn, --retires); | ||
} | ||
public static promiseTimeout<T>(promise: Promise<T>, timeout: number): Promise<T> { | ||
@@ -95,0 +113,0 @@ return new Promise<T>((resolve, reject) => { |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.53", | ||
"version": "0.0.54", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
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
116823
2101