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

util.sleep is only available inflight #5418

Open
skorfmann opened this issue Jan 4, 2024 · 4 comments
Open

util.sleep is only available inflight #5418

skorfmann opened this issue Jan 4, 2024 · 4 comments
Labels
🐛 bug Something isn't working 🎨 sdk SDK

Comments

@skorfmann
Copy link
Contributor

I tried this:

use util.sleep in preflight

This happened:

only available inflight

I expected this:

use it preflight

Is there a workaround?

was trying to use util.shell - but can't due to #5417

Anything else?

No response

Wing Version

main branch

Node.js Version

18.7

Platform(s)

MacOS

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@skorfmann skorfmann added the 🐛 bug Something isn't working label Jan 4, 2024
@monadabot monadabot added this to Wing Jan 4, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Jan 4, 2024
@skorfmann skorfmann changed the title util.sleep is only avaiable inflight util.sleep is only available inflight Jan 4, 2024
@eladb
Copy link
Contributor

eladb commented Jan 4, 2024

Can you share more details about the use case?

@skorfmann
Copy link
Contributor Author

in this particular case wanted to do testing (generating a batch of ulids in preflight).

What's the reasoning for it being inflight only?

@eladb
Copy link
Contributor

eladb commented Jan 4, 2024

What's the reasoning for it being inflight only?

It's a technical limitation. Preflight is sync while inflight is async. In JavaScript, synchronously sleeping is not really a thing, so sleeping during preflight is a bit tricky to implement (one can implement this with spawnSync() or a busy wait.

@Chriscbr
Copy link
Contributor

Chriscbr commented Jan 4, 2024

If we're running preflight code in a worker thread it could also be possible to sleep using the Atomics API:

const sleep = milliseconds => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
sleep(5000);

@staycoolcall911 staycoolcall911 moved this from 🆕 New - not properly defined to 🤝 Backlog - handoff to owners in Wing Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🎨 sdk SDK
Projects
Status: 🤝 Backlog - handoff to owners
Development

Successfully merging a pull request may close this issue.

4 participants