@softsky/utils 1.0.3 → 1.0.5

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.
package/README.md CHANGED
@@ -108,6 +108,8 @@ it will still check them by reference.
108
108
 
109
109
  ## time
110
110
  Timers, CRON, etc.
111
+ ### function measurePerformance
112
+ Measure performance of a function
111
113
  ### function cronInterval
112
114
  Like setInterval but with cron. Returns clear function.
113
115
  ### function getNextCron
package/dist/control.d.ts CHANGED
@@ -35,7 +35,7 @@ export declare function createDelayedFunction<T, V extends unknown[]>(function_:
35
35
  export declare class ImmediatePromise<T> extends Promise<T> {
36
36
  resolve: (value: T | PromiseLike<T>) => void;
37
37
  reject: (reason?: unknown) => void;
38
- constructor();
38
+ constructor(execute?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void);
39
39
  }
40
40
  /** Recursively resolves promises in objects and arrays */
41
41
  export default function deepPromiseAll<T>(input: T): Promise<AwaitedObject<T>>;
package/dist/control.js CHANGED
@@ -112,15 +112,19 @@ export function createDelayedFunction(function_, time) {
112
112
  export class ImmediatePromise extends Promise {
113
113
  resolve;
114
114
  reject;
115
- constructor() {
116
- let resolve = noop;
117
- let reject = noop;
118
- super((r, index) => {
119
- resolve = r;
120
- reject = index;
121
- });
122
- this.resolve = resolve;
123
- this.reject = reject;
115
+ constructor(execute) {
116
+ if (execute)
117
+ super(execute);
118
+ else {
119
+ let _resolve = noop;
120
+ let _reject = noop;
121
+ super((resolve, reject) => {
122
+ _resolve = resolve;
123
+ _reject = reject;
124
+ });
125
+ this.resolve = _resolve;
126
+ this.reject = _reject;
127
+ }
124
128
  }
125
129
  }
126
130
  /** Recursively resolves promises in objects and arrays */
package/dist/time.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Timers, CRON, etc.
3
3
  */
4
+ /** Measure performance of a function */
5
+ export declare function measurePerformance(function_: () => unknown, timeCheck?: number): number;
4
6
  /** Like setInterval but with cron. Returns clear function. */
5
7
  export declare function cronInterval(function_: () => unknown, cronString: string): () => void;
6
8
  /** Find next cron tick after passed date */
package/dist/time.js CHANGED
@@ -3,6 +3,16 @@
3
3
  */
4
4
  import { HOUR_MS } from './consts';
5
5
  import { ValidationError } from './errors';
6
+ /** Measure performance of a function */
7
+ export function measurePerformance(function_, timeCheck = 16.6) {
8
+ const endTime = performance.now() + timeCheck;
9
+ let executions = 0;
10
+ while (performance.now() < endTime) {
11
+ function_();
12
+ executions++;
13
+ }
14
+ return executions;
15
+ }
6
16
  /** Like setInterval but with cron. Returns clear function. */
7
17
  export function cronInterval(function_, cronString) {
8
18
  let timeout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softsky/utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "JavaScript/TypeScript utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {