@contrail/util 1.1.3-1 → 1.1.3-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,4 +19,4 @@ export declare class Timer {
|
|
|
19
19
|
private getCurrentTime;
|
|
20
20
|
}
|
|
21
21
|
export declare function delay(ms: number): Promise<unknown>;
|
|
22
|
-
export declare function timed(
|
|
22
|
+
export declare function timed(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
@@ -63,32 +63,20 @@ function delay(ms) {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
exports.delay = delay;
|
|
66
|
-
function timed(
|
|
66
|
+
function timed() {
|
|
67
67
|
return function (target, propertyKey, descriptor) {
|
|
68
68
|
const originalMethod = descriptor.value;
|
|
69
69
|
descriptor.value = function (...args) {
|
|
70
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const
|
|
72
|
-
|
|
71
|
+
const start = Date.now();
|
|
72
|
+
console.log(`⏱️ Starting ${propertyKey}`);
|
|
73
73
|
try {
|
|
74
|
-
const result = yield originalMethod.
|
|
74
|
+
const result = yield originalMethod.apply(this, args);
|
|
75
75
|
return result;
|
|
76
76
|
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
console.error(`Error in ${propertyKey}:`, error);
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
77
|
finally {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!options.threshold || duration > options.threshold) {
|
|
85
|
-
if (options.onComplete) {
|
|
86
|
-
options.onComplete(duration, propertyKey, args);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
console.log(`${propertyKey} executed in ${duration}${options.timeUnit || 'ms'}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
78
|
+
const end = Date.now();
|
|
79
|
+
console.log(`✅ ${propertyKey} completed in ${end - start}ms`);
|
|
92
80
|
}
|
|
93
81
|
});
|
|
94
82
|
};
|