Skip to content
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

Implement setTimeout/clearTimeout in Maestro's JavaScript Environment #2254

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JulienLeal
Copy link

Proposed changes

This PR implements the standard JavaScript timer functions (setTimeout/clearTimeout) in Maestro's GraalJS environment, which previously didn't include these functions.

Changes

GraalJsTimer.kt

  • Implemented new GraalJsTimer class to handle JavaScript timer functionality
  • Added thread-safe timer management using AtomicInteger
  • Implemented proper timer tracking with CountDownLatch
  • Added cleanup handling for timer resources

GraalJsEngine.kt

  • Added timer bindings to the JavaScript context
  • Exposed setTimeout and clearTimeout functions
  • Added timer cleanup in engine close

Orchestra.kt

  • Added support for waiting on active timers in script execution
  • Improved script condition handling with proper null safety
  • Added timer completion checks before finishing script execution

Implementation Details

The implementation follows JavaScript's standard timer behavior:

  • setTimeout(callback, delay, ...args) returns a numeric timer ID
  • clearTimeout(timeoutId) cancels a pending timeout
  • Timer management is thread-safe and properly cleaned up
  • Test execution waits for pending timeouts

Testing

Tested with various scenarios:

  • Short and long timeouts
  • Multiple concurrent timeouts
  • Timer cancellation
  • Resource cleanup

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.

1 participant