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

Remove unstable Deno.sleepSync #14719

Merged
merged 5 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cli/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"setRaw",
"shutdown",
"Signal",
"sleepSync",
"startTls",
"systemMemoryInfo",
"umask",
Expand Down
11 changes: 0 additions & 11 deletions cli/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,17 +731,6 @@ declare namespace Deno {
mtime: number | Date,
): Promise<void>;

/** **UNSTABLE**: new API, yet to be vetted.
*
* SleepSync puts the main thread to sleep synchronously for a given amount of
* time in milliseconds.
*
* ```ts
* Deno.sleepSync(10);
* ```
*/
export function sleepSync(millis: number): void;

/** **UNSTABLE**: new API, yet to be vetted.
*
* A generic transport listener for message-oriented protocols. */
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/testdata/worker_drop_handle_race_terminate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const WORKER2 = getCodeBlobUrl(`
// We sleep for slightly under 2 seconds in order to make sure that worker 1
// has closed, and that this worker's thread finishes normally rather than
// being killed (which happens 2 seconds after calling terminate).
Deno.sleepSync(1800);
dsherret marked this conversation as resolved.
Show resolved Hide resolved
console.log("Finished sleeping in worker 2");
setTimeout(() => {
console.log("Finished sleeping in worker 2");
}, 1800);
`);

const WORKER1 = getCodeBlobUrl(`
Expand Down
56 changes: 5 additions & 51 deletions cli/tests/unit/timers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ Deno.test(async function callbackTakesLongerThanInterval() {
const promise = deferred();

let timeEndOfFirstCallback: number | undefined;
const interval = setInterval(() => {
const interval = setInterval(async () => {
if (timeEndOfFirstCallback === undefined) {
// First callback
Deno.sleepSync(300);
dsherret marked this conversation as resolved.
Show resolved Hide resolved
await delay(300);
timeEndOfFirstCallback = Date.now();
} else {
// Second callback
Expand All @@ -236,8 +236,8 @@ Deno.test(async function clearTimeoutAfterNextTimerIsDue1() {
promise.resolve();
}, 300);

const interval = setInterval(() => {
Deno.sleepSync(400);
const interval = setInterval(async () => {
await delay(400);
// Both the interval and the timeout's due times are now in the past.
clearInterval(interval);
}, 100);
Expand All @@ -255,7 +255,7 @@ Deno.test(async function clearTimeoutAfterNextTimerIsDue2() {
promise.resolve();
}, 200);

Deno.sleepSync(300);
await delay(300);
// Both of the timeouts' due times are now in the past.
clearTimeout(timeout1);

Expand Down Expand Up @@ -531,52 +531,6 @@ Deno.test(async function timerIgnoresDateOverride() {
assertEquals(hasThrown, 1);
});

Deno.test({ permissions: { hrtime: true } }, function sleepSync() {
const start = performance.now();
Deno.sleepSync(10);
const after = performance.now();
assert(after - start >= 10);
});

Deno.test(
{ permissions: { hrtime: true } },
async function sleepSyncShorterPromise() {
const perf = performance;
const short = 5;
const long = 10;

const start = perf.now();
const p = delay(short).then(() => {
const after = perf.now();
// pending promises should resolve after the main thread comes out of sleep
assert(after - start >= long);
});
Deno.sleepSync(long);

await p;
},
);

Deno.test(
{ permissions: { hrtime: true } },
async function sleepSyncLongerPromise() {
const perf = performance;
const short = 5;
const long = 10;

const start = perf.now();
const p = delay(long).then(() => {
const after = perf.now();
// sleeping for less than the duration of a promise should have no impact
// on the resolution of that promise
assert(after - start >= long);
});
Deno.sleepSync(short);

await p;
},
);

Deno.test({
name: "unrefTimer",
permissions: { run: true, read: true },
Expand Down
5 changes: 0 additions & 5 deletions ext/web/02_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
return core.opSync("op_now");
}

function sleepSync(millis = 0) {
return core.opSync("op_sleep_sync", millis);
}

// ---------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -372,7 +368,6 @@
clearInterval,
handleTimerMacrotask,
opNow,
sleepSync,
refTimer,
unrefTimer,
};
Expand Down
2 changes: 0 additions & 2 deletions ext/web/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub use crate::message_port::MessagePort;

use crate::timers::op_now;
use crate::timers::op_sleep;
use crate::timers::op_sleep_sync;
use crate::timers::op_timer_handle;
use crate::timers::StartTime;
pub use crate::timers::TimersPermission;
Expand Down Expand Up @@ -111,7 +110,6 @@ pub fn init<P: TimersPermission + 'static>(
op_timer_handle::decl(),
op_cancel_handle::decl(),
op_sleep::decl(),
op_sleep_sync::decl::<P>(),
])
.state(move |state| {
state.put(blob_store.clone());
Expand Down
9 changes: 0 additions & 9 deletions ext/web/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,3 @@ pub async fn op_sleep(
.await?;
Ok(())
}

#[op]
pub fn op_sleep_sync<TP>(state: &mut OpState, millis: u64)
where
TP: TimersPermission + 'static,
{
state.borrow::<TP>().check_unstable(state, "Deno.sleepSync");
std::thread::sleep(Duration::from_millis(millis));
}
1 change: 0 additions & 1 deletion runtime/js/90_deno_ns.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
systemMemoryInfo: __bootstrap.os.systemMemoryInfo,
networkInterfaces: __bootstrap.os.networkInterfaces,
getUid: __bootstrap.os.getUid,
sleepSync: __bootstrap.timers.sleepSync,
listen: __bootstrap.netUnstable.listen,
connect: __bootstrap.netUnstable.connect,
listenDatagram: __bootstrap.netUnstable.listenDatagram,
Expand Down