deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

Add sleepSync helper function

Open dsherret opened this issue 2 years ago • 2 comments

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

dsherret avatar May 25 '22 01:05 dsherret

Could use the same implementation from here, which makes it possible to remove it from both instances and the subsequent failing tests from shims

MKRhere avatar May 26 '22 05:05 MKRhere

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.

dsherret avatar Jun 07 '22 18:06 dsherret

Hi @dsherret, to clarify, would you still like to see this added to the repo?

iuioiua avatar Oct 07 '22 12:10 iuioiua

@dsherret any updates on this? I'm personally against it being added but I think there should be an official decision on this.

lino-levan avatar Oct 31 '22 18:10 lino-levan

I think people can just add the code above to their projects if they really need this... it's super rare that someone would.

dsherret avatar Oct 31 '22 19:10 dsherret