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

Stabilize "Deno.sleepSync" API #14708

Closed
bartlomieju opened this issue May 23, 2022 · 6 comments · Fixed by #14719
Closed

Stabilize "Deno.sleepSync" API #14708

bartlomieju opened this issue May 23, 2022 · 6 comments · Fixed by #14719
Labels
public API related to "Deno" namespace in JS
Milestone

Comments

@bartlomieju
Copy link
Member

It's been unstable long enough, there's really not much to it.

It would allow to refactor and remove some code from deno_web extension, namely TimerPermissions trait wouldn't need to have check_unstable method.

@bartlomieju bartlomieju added the public API related to "Deno" namespace in JS label May 23, 2022
@bartlomieju bartlomieju added this to the 1.23 milestone May 23, 2022
@lucacasonato
Copy link
Member

@ry might have objections here. I know he didn't really like the API back when.

@lucacasonato
Copy link
Member

lucacasonato commented May 24, 2022

Also, we should check that the same functionality isn't already possible with just Atomics. Possibly the same functionality is available with:

const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);
const timeout = 1000; // 1s
Atomics.wait(int32, 0, 0, timeout);

@dsherret
Copy link
Member

Apparently the issue with Atomics.wait is that it doesn't currently work in the main worker context?

We discussed this super briefly in the design meeting and if there's a way we could provide a helper in deno.land/std for doing this with Atomics.wait, we think that would be preferable.

I do really think we should have a way to sleep synchronously though as it can provide a more accurate sleep mechanism for some non-web server applications (ex. when using hardware).

@ry
Copy link
Member

ry commented May 25, 2022

sleepSync has no utility - it's very easy to misuse - let's remove it not stabilize it.

@dsherret
Copy link
Member

sleepSync has no utility

...for web servers

@trgwii
Copy link
Contributor

trgwii commented May 25, 2022

It's very trivial to write a sleepSync that does this:

const end = Date.now() + 1_000;
while (Date.now() < end);

But it's fairly nontrivial to implement a sleepSync that works in all contexts and doesn't busyloop the CPU, so seems fairly reasonable to have Deno.sleepSync imo (with a big JSDoc warning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
public API related to "Deno" namespace in JS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants