X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUtils.ts;h=2f9c1ac5e92e669e7113813a378da986f8f11236;hb=cfab8dc9ea7801746461d4e8d6ac9852deb678b5;hp=851ba4318fc337474875025a85d900799ce2ebbf;hpb=17fdc576ac00c9e3a8e67a11dc2ddee9867636cc;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/Utils.ts b/ui/web/src/composables/Utils.ts index 851ba431..2f9c1ac5 100644 --- a/ui/web/src/composables/Utils.ts +++ b/ui/web/src/composables/Utils.ts @@ -1,50 +1,3 @@ -const isUndefined = (value: unknown): boolean => { - return typeof value === 'undefined'; -}; - -export const ifUndefined = (value: T | undefined, isValue: T): T => { - if (isUndefined(value) === true) return isValue; - return value as T; -}; - -// const isIterable = (obj: T): boolean => { -// if (obj === null || obj === undefined) { -// return false; -// } -// return typeof (obj as unknown as Iterable)[Symbol.iterator] === 'function'; -// }; - -// const ifNotIterableDo = (obj: T, cb: () => void): void => { -// 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); -// }; +// return (x: T) => fns.reduceRight((y, fn) => fn(y), x) +// }