Fix Await to process Go-scheduled jobs instead of blocking in js_std_loop#690
Fix Await to process Go-scheduled jobs instead of blocking in js_std_loop#690
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue where the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves a blocking issue in Await by replacing the call to js_std_loop with a cooperative polling mechanism. This new approach correctly processes jobs scheduled from Go, allowing asynchronous operations to resolve promises without deadlocking the event loop. The logic appears sound, and the accompanying test case has been appropriately updated to validate the fix. I have one minor suggestion to improve code maintainability.
context.go
Outdated
| if ctx.jobQueue != nil && len(ctx.jobQueue) > 0 { | ||
| continue // more Go jobs to process | ||
| } | ||
| time.Sleep(time.Millisecond) |
There was a problem hiding this comment.
The polling interval time.Millisecond is used here as a magic number. It's recommended to define this as a named constant at the package level (e.g., const awaitPollingInterval = time.Millisecond). This improves readability by giving the value a clear semantic name and makes it easier to configure or update in the future.
References
- Avoid using magic numbers (unnamed numerical constants) directly in code. Instead, define them as named constants to improve readability, clarity, and maintainability. This makes the purpose of the value explicit and simplifies future modifications.
There was a problem hiding this comment.
I did the change you asked for
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #690 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 11 11
Lines 2349 2355 +6
=========================================
+ Hits 2349 2355 +6
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
- the nil check on ctx.jobQueue at line 1056 is redundant since len() on a nil channel returns 0 - more coverage
|
It was funny to make a PR with agents |
|
thanks |
When using ctx.NewPromise with ctx.Schedule to resolve Promises from Go goroutines, the Await loop would block forever in js_std_loop because the C event loop doesn't know about Go's job queue.
This change replaces the js_std_loop call with cooperative polling that checks both Go jobs and JS jobs, yielding briefly between iterations. This allows async Go bridge functions to work correctly with Await.
The AwaitDrivesStdLoopForTimeout test was updated to use ctx.Schedule instead of setTimeout, since setTimeout depends on js_std_loop's internal timer handling which is no longer called.