-
Notifications
You must be signed in to change notification settings - Fork 162
feat: example of polling mirror node to simulate TopicMessageQuery #3180
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
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) |
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
84c7896
to
e33ac81
Compare
@CodiumAI-Agent /improve |
PR Code Suggestions ✨
|
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
b8df467
to
d91dba5
Compare
examples/polling-mirror-node.js
Outdated
let lastMessagesLength = 0; | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { |
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.
Suggestion: Consider using a setInterval stored in a constant so it can be cleared when needed. As it stands, this while (true) loop will run indefinitely once executed, which isn’t ideal for an example. If this is meant to demonstrate polling behavior, it's better to follow best practices by including a way to stop or clean up the polling loop.
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
examples/polling-mirror-node.js
Outdated
function pollUntilReady(dataEmitter, topicId) { | ||
let lastMessagesLength = 0; | ||
|
||
setInterval(() => { |
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.
How about assigning this interval to a timer variable that is passed as a dependency trought the function so it can be cleared when polling is no longer needed (for example when the user navigates from a page). WDYT?
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.
eslint
cries that we have added a constant that doesn't get used. I think the user can handle this and will set it to a constant and pass it to clearInterval when needed.
examples/polling-mirror-node.js
Outdated
lastMessagesLength = currentMessagesLength; | ||
} | ||
})().catch(console.error); // Handle any errors from the async function | ||
}, 1000); |
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.
How about assign this to a const variable e.g. something like POLLING_INTERVAL?
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Description:
Polling mirror node rest api to stimulate TopicMessageQuery
Notes for reviewer:
Checklist