mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
[Bun.js] Bun.sleep() lets you synchronously sleep. Thanks @evanwashere
This commit is contained in:
@@ -455,6 +455,22 @@ pub const Bun = struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sleep(
|
||||
this: void,
|
||||
ctx: js.JSContextRef,
|
||||
function: js.JSObjectRef,
|
||||
thisObject: js.JSObjectRef,
|
||||
arguments: []const js.JSValueRef,
|
||||
exception: js.ExceptionRef,
|
||||
) js.JSValueRef {
|
||||
if (js.JSValueIsNumber(ctx, arguments[0])) {
|
||||
const ms = JSValue.fromRef(arguments[0]).asNumber();
|
||||
if (ms > 0 and std.math.isFinite(ms)) std.time.sleep(@floatToInt(u64, @floor(@floatCast(f128, ms) * std.time.ns_per_ms)));
|
||||
}
|
||||
|
||||
return js.JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
var public_path_temp_str: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
|
||||
pub fn getPublicPathJS(
|
||||
@@ -493,6 +509,9 @@ pub const Bun = struct {
|
||||
.rfn = Router.match,
|
||||
.ts = Router.match_type_definition,
|
||||
},
|
||||
.sleep = .{
|
||||
.rfn = sleep,
|
||||
},
|
||||
.fetch = .{
|
||||
.rfn = Fetch.call,
|
||||
.ts = d.ts{},
|
||||
|
||||
Reference in New Issue
Block a user