deno_std
deno_std copied to clipboard
Add sleepSync helper function
Since Deno.sleepSync
is going to be removed, it would be useful to provide a helper function that uses Atomics.wait
in deno_std.
- https://github.com/denoland/deno/pull/14719
- https://github.com/denoland/deno/issues/14708#issuecomment-1135707599
Could use the same implementation from here, which makes it possible to remove it from both instances and the subsequent failing tests from shims
This is a single line of code and we want to discourage people using this (except there are obviously some use cases), so it might not be worth adding it to deno_std.
function sleepSync(ms: number) {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
}
People could also further develop this to create a more accurate sleep by spinning in certain scenarios if they need the accuracy as well.
Hi @dsherret, to clarify, would you still like to see this added to the repo?
@dsherret any updates on this? I'm personally against it being added but I think there should be an official decision on this.
I think people can just add the code above to their projects if they really need this... it's super rare that someone would.