fix: handle properly async performance storage
[e-mobility-charging-stations-simulator.git] / src / utils / Utils.ts
index 2472bf617621b87ef3752cc6000447918aa25300..458fd93065e2bd08fec1e06e7610196c7d9383f0 100644 (file)
@@ -261,6 +261,17 @@ export const clone = <T>(object: T): T => {
   return deepClone(object as CloneableData) as T
 }
 
+/**
+ * Detects whether the given value is an asynchronous function or not.
+ *
+ * @param fn - Unknown value.
+ * @returns `true` if `fn` was an asynchronous function, otherwise `false`.
+ * @internal
+ */
+export const isAsyncFunction = (fn: unknown): fn is (...args: unknown[]) => Promise<unknown> => {
+  return typeof fn === 'function' && fn.constructor.name === 'AsyncFunction'
+}
+
 export const isObject = (value: unknown): value is object => {
   return value != null && typeof value === 'object' && !Array.isArray(value)
 }