export function formatLogMessage(message: string | object) { if (typeof message === "object") { try { return JSON.stringify(message, null, 4); } catch (e) { return message.toString(); } } return message; } export interface DeferredPromise extends Promise { resolve: (value: T | PromiseLike) => void; reject: (reason?: any) => void; } export function deferred(): DeferredPromise { return (() => { let resolve!: (value: T | PromiseLike) => void; let reject!: (reason?: any) => void; let promise = new Promise((res, rej) => { resolve = res; reject = rej; }) as DeferredPromise; promise.resolve = resolve; promise.reject = reject; return promise as DeferredPromise; })(); }