mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Remove unstable Deno.sleepSync (#14719)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
e6218d9d23
commit
21dfeea3c4
9 changed files with 8 additions and 83 deletions
|
@ -52,7 +52,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
|
||||||
"setRaw",
|
"setRaw",
|
||||||
"shutdown",
|
"shutdown",
|
||||||
"Signal",
|
"Signal",
|
||||||
"sleepSync",
|
|
||||||
"startTls",
|
"startTls",
|
||||||
"systemMemoryInfo",
|
"systemMemoryInfo",
|
||||||
"umask",
|
"umask",
|
||||||
|
|
11
cli/dts/lib.deno.unstable.d.ts
vendored
11
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -751,17 +751,6 @@ declare namespace Deno {
|
||||||
mtime: number | Date,
|
mtime: number | Date,
|
||||||
): Promise<void>;
|
): 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.
|
/** **UNSTABLE**: new API, yet to be vetted.
|
||||||
*
|
*
|
||||||
* A generic transport listener for message-oriented protocols. */
|
* A generic transport listener for message-oriented protocols. */
|
||||||
|
|
|
@ -13,10 +13,10 @@ const WORKER2 = getCodeBlobUrl(`
|
||||||
console.log("Worker 2");
|
console.log("Worker 2");
|
||||||
self.postMessage(undefined);
|
self.postMessage(undefined);
|
||||||
|
|
||||||
// We sleep for slightly under 2 seconds in order to make sure that worker 1
|
// We sleep synchronously for slightly under 2 seconds in order to make sure
|
||||||
// has closed, and that this worker's thread finishes normally rather than
|
// that worker 1 has closed, and that this worker's thread finishes normally
|
||||||
// being killed (which happens 2 seconds after calling terminate).
|
// rather than being killed (which happens 2 seconds after calling terminate).
|
||||||
Deno.sleepSync(1800);
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1800);
|
||||||
console.log("Finished sleeping in worker 2");
|
console.log("Finished sleeping in worker 2");
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ function runFlockTestProcess(opts: { exclusive: boolean; sync: boolean }) {
|
||||||
// the lock so that the enter time of the next process doesn't
|
// the lock so that the enter time of the next process doesn't
|
||||||
// occur at the same time as this exit time
|
// occur at the same time as this exit time
|
||||||
const exitTime = new Date().getTime();
|
const exitTime = new Date().getTime();
|
||||||
Deno.sleepSync(100);
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
|
|
||||||
// release the lock
|
// release the lock
|
||||||
${opts.sync ? "Deno.funlockSync(rid);" : "await Deno.funlock(rid);"}
|
${opts.sync ? "Deno.funlockSync(rid);" : "await Deno.funlock(rid);"}
|
||||||
|
|
|
@ -215,7 +215,7 @@ Deno.test(async function callbackTakesLongerThanInterval() {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
if (timeEndOfFirstCallback === undefined) {
|
if (timeEndOfFirstCallback === undefined) {
|
||||||
// First callback
|
// First callback
|
||||||
Deno.sleepSync(300);
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 300);
|
||||||
timeEndOfFirstCallback = Date.now();
|
timeEndOfFirstCallback = Date.now();
|
||||||
} else {
|
} else {
|
||||||
// Second callback
|
// Second callback
|
||||||
|
@ -237,7 +237,7 @@ Deno.test(async function clearTimeoutAfterNextTimerIsDue1() {
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
Deno.sleepSync(400);
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 400);
|
||||||
// Both the interval and the timeout's due times are now in the past.
|
// Both the interval and the timeout's due times are now in the past.
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
}, 100);
|
}, 100);
|
||||||
|
@ -255,7 +255,7 @@ Deno.test(async function clearTimeoutAfterNextTimerIsDue2() {
|
||||||
promise.resolve();
|
promise.resolve();
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
Deno.sleepSync(300);
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 300);
|
||||||
// Both of the timeouts' due times are now in the past.
|
// Both of the timeouts' due times are now in the past.
|
||||||
clearTimeout(timeout1);
|
clearTimeout(timeout1);
|
||||||
|
|
||||||
|
@ -531,52 +531,6 @@ Deno.test(async function timerIgnoresDateOverride() {
|
||||||
assertEquals(hasThrown, 1);
|
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({
|
Deno.test({
|
||||||
name: "unrefTimer",
|
name: "unrefTimer",
|
||||||
permissions: { run: true, read: true },
|
permissions: { run: true, read: true },
|
||||||
|
|
|
@ -28,10 +28,6 @@
|
||||||
return core.opSync("op_now");
|
return core.opSync("op_now");
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleepSync(millis = 0) {
|
|
||||||
return core.opSync("op_sleep_sync", millis);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -372,7 +368,6 @@
|
||||||
clearInterval,
|
clearInterval,
|
||||||
handleTimerMacrotask,
|
handleTimerMacrotask,
|
||||||
opNow,
|
opNow,
|
||||||
sleepSync,
|
|
||||||
refTimer,
|
refTimer,
|
||||||
unrefTimer,
|
unrefTimer,
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,7 +52,6 @@ pub use crate::message_port::MessagePort;
|
||||||
|
|
||||||
use crate::timers::op_now;
|
use crate::timers::op_now;
|
||||||
use crate::timers::op_sleep;
|
use crate::timers::op_sleep;
|
||||||
use crate::timers::op_sleep_sync;
|
|
||||||
use crate::timers::op_timer_handle;
|
use crate::timers::op_timer_handle;
|
||||||
use crate::timers::StartTime;
|
use crate::timers::StartTime;
|
||||||
pub use crate::timers::TimersPermission;
|
pub use crate::timers::TimersPermission;
|
||||||
|
@ -111,7 +110,6 @@ pub fn init<P: TimersPermission + 'static>(
|
||||||
op_timer_handle::decl(),
|
op_timer_handle::decl(),
|
||||||
op_cancel_handle::decl(),
|
op_cancel_handle::decl(),
|
||||||
op_sleep::decl(),
|
op_sleep::decl(),
|
||||||
op_sleep_sync::decl::<P>(),
|
|
||||||
])
|
])
|
||||||
.state(move |state| {
|
.state(move |state| {
|
||||||
state.put(blob_store.clone());
|
state.put(blob_store.clone());
|
||||||
|
|
|
@ -82,12 +82,3 @@ pub async fn op_sleep(
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
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));
|
|
||||||
}
|
|
||||||
|
|
|
@ -126,7 +126,6 @@
|
||||||
networkInterfaces: __bootstrap.os.networkInterfaces,
|
networkInterfaces: __bootstrap.os.networkInterfaces,
|
||||||
getGid: __bootstrap.os.getGid,
|
getGid: __bootstrap.os.getGid,
|
||||||
getUid: __bootstrap.os.getUid,
|
getUid: __bootstrap.os.getUid,
|
||||||
sleepSync: __bootstrap.timers.sleepSync,
|
|
||||||
listen: __bootstrap.netUnstable.listen,
|
listen: __bootstrap.netUnstable.listen,
|
||||||
connect: __bootstrap.netUnstable.connect,
|
connect: __bootstrap.netUnstable.connect,
|
||||||
listenDatagram: __bootstrap.netUnstable.listenDatagram,
|
listenDatagram: __bootstrap.netUnstable.listenDatagram,
|
||||||
|
|
Loading…
Add table
Reference in a new issue