mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 11:33:02 +00:00
feat: print performance logs to console.
This commit is contained in:
@@ -8,6 +8,6 @@ export class DecryptionQueue extends ConcurrentQueue<{ id: string; blobURI: stri
|
||||
}
|
||||
|
||||
async handler(item: { id: string; blobURI: string }): Promise<DecryptionResult> {
|
||||
return this.workerClientBus.request(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, item.blobURI);
|
||||
return this.workerClientBus.request(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ test('should be able to forward request to worker client bus', async () => {
|
||||
const queue = new DecryptionQueue(bus, 1);
|
||||
await expect(queue.add({ id: 'file://1', blobURI: 'blob://mock-file' })).resolves.toEqual({
|
||||
actionName: DECRYPTION_WORKER_ACTION_NAME.DECRYPT,
|
||||
payload: 'blob://mock-file',
|
||||
payload: {
|
||||
blobURI: 'blob://mock-file',
|
||||
id: 'file://1',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
22
src/util/timedLogger.ts
Normal file
22
src/util/timedLogger.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
function isPromise<T = unknown>(p: unknown): p is Promise<T> {
|
||||
return !!p && typeof p === 'object' && 'then' in p && 'catch' in p && 'finally' in p;
|
||||
}
|
||||
|
||||
export function timedLogger<R = unknown>(label: string, fn: () => R): R {
|
||||
console.time(label);
|
||||
|
||||
try {
|
||||
const result = fn();
|
||||
|
||||
if (isPromise(result)) {
|
||||
result.finally(() => {
|
||||
console.timeEnd(label);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.timeEnd(label);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user