X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUtils.ts;h=07848f36d41b8a8f285ae817b117ddaf6bdb2178;hb=98262391ccaa5d00fac1ec8a1707d7fbba33cc3a;hp=cf4baf5d5fe9c8b569359d248daea9b82160e917;hpb=f568f36861d62d759a95b17fbe10380eca88a71b;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/Utils.ts b/ui/web/src/composables/Utils.ts index cf4baf5d..07848f36 100644 --- a/ui/web/src/composables/Utils.ts +++ b/ui/web/src/composables/Utils.ts @@ -1,5 +1,3 @@ -import util from 'node:util'; - const isUndefined = (value: unknown): boolean => { return typeof value === 'undefined'; }; @@ -20,33 +18,6 @@ export const ifUndefined = (value: T | undefined, isValue: T): T => { // if (isIterable(obj) === false) cb(); // }; -const isPromisePending = (promise: Promise): boolean => { - return util.inspect(promise).includes('pending'); -}; - -export const promiseWithTimeout = ( - promise: Promise, - timeoutMs: number, - timeoutError: Error, - timeoutCallback: () => void = () => { - /* This is intentional */ - } -): Promise => { - // Create a timeout promise that rejects in timeout milliseconds - const timeoutPromise = new Promise((_, 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([promise, timeoutPromise]); -}; - // export const compose = (...fns: ((arg: T) => T)[]): ((x: T) => T) => { // return (x: T) => fns.reduceRight((y, fn) => fn(y), x); // };