-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert util TimeUtils to TS #19
Conversation
packages/utils/src/TimeUtils.ts
Outdated
@@ -29,7 +29,7 @@ class TimeUtils { | |||
* Minutes aren't paded, as thats a slower change | |||
* @param {integer} time in seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with TypeScript, since the type is defined in the function itself, we don't need to include it in the docs anymore:
* @param {integer} time in seconds | |
* @param time in seconds |
Granted integer
isn't a valid type in TypeScript (or JS), only number
is. So in this case, I think we should use a type alias to define a new type: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-aliases
We could just define type integer = number
above, with a comment that we expect integers, then we can use the integer
type here instead of number
. Alternatively could name the type something time specific, like TimeInSeconds
or something like that, but that may be getting too specific. I leave the name to your judgment.
packages/utils/src/TimeUtils.ts
Outdated
@@ -73,7 +76,7 @@ class TimeUtils { | |||
* Parse time in seconds from the provided time string | |||
* @param {string} timeString Time string in hh:mm:ss format | |||
*/ | |||
static parseTime(timeString) { | |||
static parseTime(timeString: string): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you suggested in your comment, we can specify a better type using Type Literals: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
In this case in particular, we can define a TimeString
type, something like:
type TimeString = `${number}:${number}:${number}`;
Of course, that would match something like 0:4325423985:3928932
, which is obviously not a valid time string. I don't know if there's an even better way to write it, but even defining a type alias with a comment of the format will be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. In retrospect we should probably use Duration instead of Time to describe these things, but NBD
fixes #1439 - Heap usage code now guarantees that new requests won't be scheduled until all previous requests are complete. ## Testing I tested by shutting my Mac for ~2 hours and returning. Timings looks something like this: ### Summary <img width="310" alt="image" src="https://github.com/deephaven/web-client-ui/assets/1900643/0ad2d426-2fed-48e8-a255-989ee5d524f3"> It seems that requests still happen occasionally while sleeping. On Wake up, there were a few ticks resulting in "Unable to get heap usage" console errors. Then a prompt showed up indicating credentials had expired at which point requests start succeeding again. ### Full Console Log ``` useAsyncInterval.ts:37 [useAsyncInterval] tick #1. 10068 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9918 useAsyncInterval.ts:37 [useAsyncInterval] tick #2. 9936 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #3. 10026 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9958 useAsyncInterval.ts:62 [useAsyncInterval] Setting interval minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #1. 941977 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #2. 13 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #3. 2038465 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #4. 19 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #5. 537820 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #6. 16 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #7. 191633 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #8. 18 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #9. 23720 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #10. 18 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #11. 886367 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #12. 17 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #13. 1010951 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #14. 6 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #15. 650011 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #16. 13 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #17. 731687 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #18. 19 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #19. 120545 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #20. 16 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #21. 446345 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0 useAsyncInterval.ts:37 [useAsyncInterval] tick #22. 13 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #23. 10999 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 8987 useAsyncInterval.ts:37 [useAsyncInterval] tick #24. 9020 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #25. 10030 ms elapsed since last tick. HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9955 useAsyncInterval.ts:37 [useAsyncInterval] tick #26. 9979 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #27. 10027 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9956 useAsyncInterval.ts:62 [useAsyncInterval] Setting interval minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #1. 10695 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9290 useAsyncInterval.ts:37 [useAsyncInterval] tick #2. 9311 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000 useAsyncInterval.ts:37 [useAsyncInterval] tick #3. 10017 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9969 useAsyncInterval.ts:37 [useAsyncInterval] tick #4. 9992 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9992 useAsyncInterval.ts:37 [useAsyncInterval] tick #5. 10680 ms elapsed since last tick. useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9308 ```
Was wondering if we could do a custom type for time as
XX:XX:XX
but otherwise pretty straightforward.