async function retryAsyncFunction(retries, delay, func, ...args) {
  let attempt = 0;
  while (attempt < retries) {
    try {
      const result = await func(...args);
      return result;
    } catch (error) {
      attempt++;
      if (attempt < retries) {
        await new Promise(resolve => setTimeout(resolve, delay));
      } else {
        throw error;
      }
    }
  }
}
Generic function for retrying an async function
@param {number} retries
@param {number} delay
@param {Function} func
@param {any[]} args