-
Notifications
You must be signed in to change notification settings - Fork 5
Add or update Polling in Glossary #77
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
WalkthroughA new glossary entry titled "API Polling: Comprehensive Guide" has been added to the documentation. This entry explains the concept of API polling, its mechanics, use cases, alternatives, best practices, code examples, historical context, FAQs, and future directions, all structured with appropriate metadata for glossary integration. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (3)
apps/www/content/glossary/polling.mdx (3)
2-6
: Populatecategories
and tone-down the marketing-style descriptionThe description reads like marketing copy and the
categories
array is empty, which prevents proper indexing in the docs site.-description: Unlock API Polling power. Learn essentials, key takeaways from real-world examples. Understand API Polling vs Webhooks. +description: Understand how API polling works, when to use it, and how it compares to alternatives such as webhooks and WebSockets. -categories: [] +categories: + - APIs + - Architecture + - Glossary
28-33
: Replace unrelated “recommendedReading” links with API-focused resourcesThe current links point to political-polling sites and an IETF draft unrelated to API polling.
- - url: https://en.wikipedia.org/wiki/Opinion_poll - title: Opinion Poll - Wikipedia - - url: https://datatracker.ietf.org/doc/polls-123-masque-202507221130/ - title: "Polls IETF123: masque - IETF Datatracker" - - url: https://www.realclearpolling.com/ - title: RealClearPolling - Real-Time Polling Data + - url: https://developer.mozilla.org/en-US/docs/Web/API/fetch#checking_for_updates_polling + title: MDN – Polling with Fetch + - url: https://realtimeapi.io/articles/polling-long-polling-and-websockets + title: Polling, Long-Polling, and WebSockets – Real-Time API Reference + - url: https://cloud.google.com/apis/design/polling + title: Google Cloud API Design – Polling guidelines
99-106
: Mention bothIf-Modified-Since
andIf-None-Match
for conditional requestsOnly
If-None-Match
is referenced; addingIf-Modified-Since
makes the guidance more complete.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/www/content/glossary/polling.mdx
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*
📄 CodeRabbit Inference Engine (.cursor/rules/analyze-issue.mdc)
Enforce 300-line file limit where applicable
Files:
apps/www/content/glossary/polling.mdx
Here’s a simple **API polling example** in TypeScript using ESM syntax: | ||
|
||
```typescript | ||
import axios from 'axios'; | ||
|
||
const poll = async (url: string, interval: number) => { | ||
try { | ||
const response = await axios.get(url); | ||
console.log('Data:', response.data); | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} finally { | ||
setTimeout(() => poll(url, interval), interval); | ||
} | ||
}; | ||
|
||
poll('https://api.example.com/data', 5000); // Polls every 5 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.
🛠️ Refactor suggestion
Add cancellation & prevent unbounded timers in the TypeScript example
The recursive setTimeout
loop never stops, which can leak timers. Expose an AbortSignal
so callers can cancel polling.
-const poll = async (url: string, interval: number) => {
+const poll = async (url: string, interval: number, abortSignal?: AbortSignal) => {
try {
const response = await axios.get(url);
console.log('Data:', response.data);
} catch (error) {
console.error('Error:', error);
} finally {
- setTimeout(() => poll(url, interval), interval);
+ if (!abortSignal?.aborted) {
+ setTimeout(() => poll(url, interval, abortSignal), interval);
+ }
}
};
-poll('https://api.example.com/data', 5000); // Polls every 5 seconds
+const controller = new AbortController();
+poll('https://api.example.com/data', 5000, controller.signal); // Polls every 5 s
+// Call controller.abort() to stop polling
📝 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.
Here’s a simple **API polling example** in TypeScript using ESM syntax: | |
```typescript | |
import axios from 'axios'; | |
const poll = async (url: string, interval: number) => { | |
try { | |
const response = await axios.get(url); | |
console.log('Data:', response.data); | |
} catch (error) { | |
console.error('Error:', error); | |
} finally { | |
setTimeout(() => poll(url, interval), interval); | |
} | |
}; | |
poll('https://api.example.com/data', 5000); // Polls every 5 seconds | |
``` |
🤖 Prompt for AI Agents
In apps/www/content/glossary/polling.mdx around lines 60 to 77, the TypeScript
polling example uses a recursive setTimeout loop that never stops, causing
potential timer leaks. Modify the poll function to accept an AbortSignal
parameter and check its aborted state before scheduling the next poll. Use the
signal's abort event to cancel any pending timers, allowing callers to stop
polling and prevent unbounded timers.
This PR adds or updates the Polling.mdx file in the API documentation.
Summary by CodeRabbit