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

Making SetTimeout and co. globally available by default #3589

Closed
mstoykov opened this issue Feb 9, 2024 · 6 comments
Closed

Making SetTimeout and co. globally available by default #3589

mstoykov opened this issue Feb 9, 2024 · 6 comments
Assignees
Milestone

Comments

@mstoykov
Copy link
Contributor

mstoykov commented Feb 9, 2024

Feature Description

Make the newly stabilized k6/timers exports:

  1. SetTimeout
  2. SetInterval
  3. ClearTimeout
  4. ClearInterval

globally available

Suggested Solution (optional)

Keep the module, and just have code that imports and set them on globalThis by default that is run an VU initialization.

Already existing or connected issues / PRs (optional)

Stabilization PR #3587
Original stabilization issue #3297
SetTimeout not being globally available #3329

@mstoykov mstoykov added this to the v0.50.0 milestone Feb 9, 2024
@olegbespalov
Copy link
Contributor

I feel that having these functions globally accessible is what users will expect. However, I can't say I'm a JavaScript expert, so I am unsure if my feelings are relevant.

@joanlopez
Copy link
Contributor

Similar to @olegbespalov, not a JS expert neither, but I guess that's what experienced JS users would expect, while for the rest it doesn't matter. So 👍🏻

@oleiade
Copy link
Member

oleiade commented Feb 12, 2024

For clarification and my understanding, what does the target user-experience look like?

My assumption reading this is:

// No need to import the `k6/timers` module

export default function () {
    setTimeout(...)  // timer functions are available in the runtime "natively", like in v8 browser runtimes
    setInterval(...)
    clearTimeout(...)
    clearInterval(...)
 }

If so, I think that makes a lot of sense, and although I'm not completely set on that, it is also something we might want to consider also for "Web APIs" we integrate in the future (webcrypto, streams, fetch (if we do), etc...) to provide a user-experience close to what is available in other runtimes.

🙇🏻

@mstoykov
Copy link
Contributor Author

Yes, that will be a thing that users will be able to do - without needing to import anything

@amills-vibeirl
Copy link

amills-vibeirl commented Feb 28, 2024

there is no event loop in Goja (TMK). So I am not sure who/what would call the global setInterval. Using Goja for this lib seems like a terrible mistake and frankly I am gonna run as far as I can in another direction (no offense but hopefully this helps other people..)

@mstoykov
Copy link
Contributor Author

@amills-vibeirl, while goja doesn't have an event loop in itself, k6 adds one. As will most projects using any js engine that want to have control over its event loop.

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

No branches or pull requests

5 participants