Skip to content

Conversation

@nicolaschan
Copy link
Contributor

@nicolaschan nicolaschan commented Sep 2, 2025

As mentioned in issue #567 the README needs a few fixes to get the examples working. I've tested these by running them in the JavaScript console.

Summary by CodeRabbit

  • Refactor

    • Group-related operations are now synchronous.
    • Renamed APIs for creating/appending groups and fetching the next group.
    • Publishing now requires passing a consumed payload rather than a producer.
    • Announcement discovery switches from async-iterable loops to an explicit next()-based iteration.
  • Documentation

    • Updated examples and guidance to reflect the new synchronous operations, publishing flow, and iteration patterns.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

README examples in js/moq were updated to reflect API changes: renamed Track methods (createGroup→appendGroup, next→nextGroup), Group methods made synchronous (writeString, close), publish now uses broadcast.consume(), and announcement discovery switched from async iteration to a manual next()-based loop.

Changes

Cohort / File(s) Summary
Publishing API updates
js/moq/README.md
Updated examples: Track.createGroup() → Track.appendGroup(); Group.writeString() and Group.close() now synchronous; connection.publish() now passes broadcast.consume() instead of a producer.
Subscribing/Track API
js/moq/README.md
Renamed Track.next() → Track.nextGroup() in subscription examples.
Discovery iteration
js/moq/README.md
Changed announcement iteration from for-await-of (AsyncIterable) to explicit next()-loop pattern.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App
  participant Connection
  participant Broadcast
  participant Track
  participant Group

  App->>Connection: publish("my-broadcast", Broadcast.consume())
  Note right of Connection: Second arg is consumed form

  App->>Track: appendGroup()
  Track-->>App: Group
  App->>Group: writeString("...")
  App->>Group: close()
Loading
sequenceDiagram
  autonumber
  actor App
  participant Track
  participant Announced as AnnouncedIterator

  App->>Track: nextGroup()
  Track-->>App: Group | null

  App->>Announced: next()
  Announced-->>App: Announcement | null
  App->>Announced: next() (loop until null)
  Note over App,Announced: Replaces for-await-of with manual next()
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws at APIs anew,
appendGroup hops in, nextGroup too!
I nibble bytes, then close—no wait—
consume the stream, publish it straight.
Announcements peek with next, not lore—
a tidy trail of carrots galore. 🥕🐇

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nicolaschan nicolaschan force-pushed the nicolaschan/update-readme branch from 1ef268d to 9aa783d Compare September 2, 2025 04:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
js/moq/README.md (5)

55-55: Confirm publish() sync/async and await if Promise

If connection.publish returns a Promise, await it before logging to avoid a misleading success message; otherwise, keep as-is.

-connection.publish("my-broadcast", broadcast.consume());
+await connection.publish("my-broadcast", broadcast.consume());

74-74: Fix markdownlint MD010: replace hard tab with spaces

The code block line uses a hard tab. Replace with spaces to satisfy markdownlint.

-for (;;) {
-	const group = await track.nextGroup();
+for (;;) {
+  const group = await track.nextGroup();

96-105: Stream discovery loop can be simplified

Use a compact for-loop form to avoid duplicating announced.next() and reduce chances of mistakes.

-let announcement = await announced.next();
-while (announcement) {
+for (let announcement = await announced.next(); announcement; announcement = await announced.next()) {
     console.log("New stream available:", announcement.name);

     // Subscribe to new streams
     const broadcast = connection.consume(announcement.name);
     // ... handle the broadcast
-
-    announcement = await announced.next();
 }

11-11: Typo: “Specificially” → “Specifically”

User-facing docs—fix the spelling.

-Specificially, this package implements the networking layer called [moq-lite](https://moq.dev/blog/moq-lite).
+Specifically, this package implements the networking layer called [moq-lite](https://moq.dev/blog/moq-lite).

12-12: Broken/missing link target

Markdown link “[../hang]” lacks a URL. Either make it a relative link or convert to plain text.

-Check out [../hang] for a higher-level media library that uses this package.
+Check out [../hang](../hang) for a higher-level media library that uses this package.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 86c0f57 and 9aa783d.

📒 Files selected for processing (1)
  • js/moq/README.md (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
js/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place JS/TS packages under the js/ directory

Files:

  • js/moq/README.md
🪛 markdownlint-cli2 (0.17.2)
js/moq/README.md

74-74: Hard tabs
Column: 1

(MD010, no-hard-tabs)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Check
🔇 Additional comments (1)
js/moq/README.md (1)

50-56: Overall: examples now match the current API

The switch to appendGroup(), nextGroup(), and announced.next() aligns with the described API changes; examples are coherent and easier to follow.

Also applies to: 74-84, 96-105

Comment on lines +50 to +52
const group = track.appendGroup();
group.writeString("Hello, MoQ!");
group.close();
Copy link
Contributor

@coderabbitai coderabbitai bot Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Close groups in finally to avoid leaks if write throws

Given writeString/close are now sync, ensure the group is always closed even if writeString throws.

-const group = track.appendGroup();
-group.writeString("Hello, MoQ!");
-group.close();
+const group = track.appendGroup();
+try {
+  group.writeString("Hello, MoQ!");
+} finally {
+  group.close();
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const group = track.appendGroup();
group.writeString("Hello, MoQ!");
group.close();
const group = track.appendGroup();
try {
group.writeString("Hello, MoQ!");
} finally {
group.close();
}
🤖 Prompt for AI Agents
In js/moq/README.md around lines 50 to 52, the example opens a group then calls
writeString and close but does not guarantee close if writeString throws; update
the snippet to acquire the group, perform writeString inside a try block, and
call group.close() in a finally block so the group is always closed even on
synchronous exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel for an example like this it's best to keep it to the minimum needed for a working example. In production code they can put it in finally, as is standard practice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolaschan You make a great point! You're absolutely right that README examples should focus on demonstrating the core API clearly and concisely. The try-finally pattern, while important for production code, would add unnecessary complexity to what should be a straightforward example of the MoQ publishing flow. I'll keep this in mind for future reviews. Thanks for the clarification!

🐰✨ (Understanding the balance between clarity and completeness in documentation!)


✏️ Learnings added
Learnt from: nicolaschan
PR: kixelated/moq#568
File: js/moq/README.md:50-52
Timestamp: 2025-09-02T04:35:10.211Z
Learning: For README examples in the moq repository, prefer minimal working examples that demonstrate core API usage clearly, rather than including production-level error handling patterns like try-finally blocks. Production concerns should be left for actual implementation.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@kixelated kixelated merged commit dd3cffc into moq-dev:main Sep 2, 2025
8 checks passed
@kixelated
Copy link
Collaborator

thx. And I'll move these examples into .ts files so they get updated when I change things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants