In Bigquery does not exist a native function like DBMS_LOCK.SLEEP (or DBMS_SESSION.SLEEP) from Oracle ("Puts a procedure to sleep for a specific time"). I tried to use an UDF with JavaScript code but it does not work as I expect: it does not stop other than forced. Can you help me understand what's going on? Thanks!
CREATE TEMP FUNCTION JS_Sleep(x FLOAT64)
RETURNS FLOAT64
LANGUAGE js AS r"""
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
return sleep(x);
""";
select JS_Sleep(10000);
const targetDate= Date.now() + milliseconds; while(Date.now()<targetDate){}- aaaalsofunction busySleep