mirror of
https://github.com/oven-sh/bun
synced 2026-02-17 06:12:08 +00:00
setImmediate
This commit is contained in:
@@ -161,16 +161,12 @@ pub const All = struct {
|
||||
// prevent libuv from polling forever
|
||||
}
|
||||
}.cb);
|
||||
} else {
|
||||
vm.uwsLoop().ref();
|
||||
}
|
||||
} else if (old > 0 and new <= 0) {
|
||||
if (comptime Environment.isWindows) {
|
||||
if (this.uv_idle.data != null) {
|
||||
this.uv_idle.stop();
|
||||
}
|
||||
} else {
|
||||
vm.uwsLoop().unref();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,6 +205,10 @@ pub const All = struct {
|
||||
|
||||
pub fn getTimeout(this: *All, spec: *timespec, vm: *VirtualMachine) bool {
|
||||
if (this.active_timer_count == 0) {
|
||||
if (vm.eventLoop().immediate_tasks.items.len > 0) {
|
||||
spec.* = .{ .nsec = 0, .sec = 0 };
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -234,11 +234,19 @@ pub const All = struct {
|
||||
},
|
||||
.lt => {
|
||||
spec.* = min.next.duration(&now);
|
||||
if (vm.eventLoop().immediate_tasks.items.len > 0) {
|
||||
spec.* = .{ .nsec = 0, .sec = 0 };
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.eventLoop().immediate_tasks.items.len > 0) {
|
||||
spec.* = .{ .nsec = 0, .sec = 0 };
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1526,11 +1526,6 @@ pub const EventLoop = struct {
|
||||
var ctx = this.virtual_machine;
|
||||
|
||||
this.tickImmediateTasks(ctx);
|
||||
if (comptime Environment.isPosix) {
|
||||
if (this.immediate_tasks.items.len > 0) {
|
||||
this.wakeup();
|
||||
}
|
||||
}
|
||||
|
||||
if (comptime Environment.isPosix) {
|
||||
// Some tasks need to keep the event loop alive for one more tick.
|
||||
@@ -1553,6 +1548,7 @@ pub const EventLoop = struct {
|
||||
var event_loop_sleep_timer = if (comptime Environment.isDebug) std.time.Timer.start() catch unreachable;
|
||||
// for the printer, this is defined:
|
||||
var timespec: bun.timespec = if (Environment.isDebug) .{ .sec = 0, .nsec = 0 } else undefined;
|
||||
|
||||
loop.tickWithTimeout(if (ctx.timer.getTimeout(×pec, ctx)) ×pec else null);
|
||||
|
||||
if (comptime Environment.isDebug) {
|
||||
@@ -1611,11 +1607,6 @@ pub const EventLoop = struct {
|
||||
var ctx = this.virtual_machine;
|
||||
|
||||
this.tickImmediateTasks(ctx);
|
||||
if (comptime Environment.isPosix) {
|
||||
if (this.immediate_tasks.items.len > 0) {
|
||||
this.wakeup();
|
||||
}
|
||||
}
|
||||
|
||||
if (comptime Environment.isPosix) {
|
||||
const pending_unref = ctx.pending_unref_counter;
|
||||
|
||||
Reference in New Issue
Block a user