fix: ensure OCPP request timeouting cancel it
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index add232ac159f8976b557efbdb56ac37f6685652b..efdffc2f2bdc5b59b12acaf55a425a200982b86f 100644 (file)
@@ -1,6 +1,5 @@
 import { randomBytes, randomInt, randomUUID, webcrypto } from 'node:crypto';
 import { env, nextTick } from 'node:process';
-import { inspect } from 'node:util';
 
 import {
   formatDuration,
@@ -331,33 +330,6 @@ export const exponentialDelay = (retryNumber = 0, delayFactor = 100): number =>
   return delay + randomSum;
 };
 
-const isPromisePending = (promise: Promise<unknown>): boolean => {
-  return inspect(promise).includes('pending');
-};
-
-export const promiseWithTimeout = async <T>(
-  promise: Promise<T>,
-  timeoutMs: number,
-  timeoutError: Error,
-  timeoutCallback: () => void = () => {
-    /* This is intentional */
-  },
-): Promise<T> => {
-  // Creates a timeout promise that rejects in timeout milliseconds
-  const timeoutPromise = new Promise<never>((_, reject) => {
-    setTimeout(() => {
-      if (isPromisePending(promise)) {
-        timeoutCallback();
-        // FIXME: The original promise shall be canceled
-      }
-      reject(timeoutError);
-    }, timeoutMs);
-  });
-
-  // Returns a race between timeout promise and the passed promise
-  return Promise.race<T>([promise, timeoutPromise]);
-};
-
 /**
  * Generates a cryptographically secure random number in the [0,1[ range
  *