Expand hrtime utility to support Web Workers.#70
Conversation
📝 WalkthroughWalkthrough
ChangesWeb Worker hrtime Support
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/dicom-codec/src/utils/processTimer.js`:
- Around line 16-20: The hrtime function has an inconsistent return type that
causes crashes when the return value is indexed. The JSDoc currently indicates
the return type can be either a tuple [number, number] or a plain number, but
the code at line 54 always indexes into the result with [0] and [1]. Update the
JSDoc in the comment block to only specify [number, number] as the return type,
and then locate the return statement around line 50 that currently returns the
numeric value 0 and change it to return a tuple format [0, 0] to maintain
consistency with the expected contract that all code paths return a tuple.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2e5e1c9a-983b-4a0f-a485-f2b145f2c215
📒 Files selected for processing (1)
packages/dicom-codec/src/utils/processTimer.js
| /** | ||
| * | ||
| * @return {[number, number]|number} | ||
| * @param previousTime{[number, number]} | ||
| */ |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Make hrtime return shape consistent across all branches.
Line 50 returns 0, but downstream code assumes a tuple and indexes time[0]/time[1] (Line 54). In unsupported runtimes this can still crash. Keep the contract tuple-only and align JSDoc accordingly.
Proposed fix
/**
- *
- * `@return` {[number, number]|number}
- * `@param` previousTime{[number, number]}
+ * `@param` {[number, number]} [previousTime]
+ * `@returns` {[number, number]}
*/
function hrtime(previousTime) {
@@
- // Return [0, 0] to avoid crash in other environments?
- return 0;
+ // Fallback: preserve tuple contract to avoid downstream crashes.
+ return [0, 0];
}Also applies to: 49-50
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/dicom-codec/src/utils/processTimer.js` around lines 16 - 20, The
hrtime function has an inconsistent return type that causes crashes when the
return value is indexed. The JSDoc currently indicates the return type can be
either a tuple [number, number] or a plain number, but the code at line 54
always indexes into the result with [0] and [1]. Update the JSDoc in the comment
block to only specify [number, number] as the return type, and then locate the
return statement around line 50 that currently returns the numeric value 0 and
change it to return a tuple format [0, 0] to maintain consistency with the
expected contract that all code paths return a tuple.
Hi,
I need to use the dicom codecs inside a worker for applying redaction into the pixel data; I got a crash from the
processTimer.jsutil.I tried this locally and it's now working.
I have also a question about the default return value; it is not preferable to return
[0,0]instead of0to avoid crashing in other environments. The only downside is having a false duration given by this util.Have a nice day.
Summary by CodeRabbit
Bug Fixes
Documentation