mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
Merge pull request #780 from lightpanda-io/fix_loop_run_wait
Fix loop run (Page.wait)
This commit is contained in:
@@ -81,12 +81,13 @@ pub const Loop = struct {
|
|||||||
|
|
||||||
// run tail events. We do run the tail events to ensure all the
|
// run tail events. We do run the tail events to ensure all the
|
||||||
// contexts are correcly free.
|
// contexts are correcly free.
|
||||||
while (self.hasPendinEvents()) {
|
while (self.pending_network_count != 0 or self.pending_timeout_count != 0) {
|
||||||
self.io.run_for_ns(10 * std.time.ns_per_ms) catch |err| {
|
self.io.run_for_ns(std.time.ns_per_ms * 10) catch |err| {
|
||||||
log.err(.loop, "deinit", .{ .err = err });
|
log.err(.loop, "deinit", .{ .err = err });
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comptime CANCEL_SUPPORTED) {
|
if (comptime CANCEL_SUPPORTED) {
|
||||||
self.io.cancel_all();
|
self.io.cancel_all();
|
||||||
}
|
}
|
||||||
@@ -96,21 +97,6 @@ pub const Loop = struct {
|
|||||||
self.cancelled.deinit(self.alloc);
|
self.cancelled.deinit(self.alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can shutdown once all the pending network IO is complete.
|
|
||||||
// In debug mode we also wait until al the pending timeouts are complete
|
|
||||||
// but we only do this so that the `timeoutCallback` can free all allocated
|
|
||||||
// memory and we won't report a leak.
|
|
||||||
fn hasPendinEvents(self: *const Self) bool {
|
|
||||||
if (self.pending_network_count > 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (builtin.mode != .Debug) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return self.pending_timeout_count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve all registred I/O events completed by OS kernel,
|
// Retrieve all registred I/O events completed by OS kernel,
|
||||||
// and execute sequentially their callbacks.
|
// and execute sequentially their callbacks.
|
||||||
// Stops when there is no more I/O events registered on the loop.
|
// Stops when there is no more I/O events registered on the loop.
|
||||||
@@ -121,9 +107,11 @@ pub const Loop = struct {
|
|||||||
self.stopping = true;
|
self.stopping = true;
|
||||||
defer self.stopping = false;
|
defer self.stopping = false;
|
||||||
|
|
||||||
while (self.pending_network_count > 0) {
|
while (self.pending_network_count != 0 or self.pending_timeout_count != 0) {
|
||||||
try self.io.run_for_ns(10 * std.time.ns_per_ms);
|
self.io.run_for_ns(std.time.ns_per_ms * 10) catch |err| {
|
||||||
// at each iteration we might have new events registred by previous callbacks
|
log.err(.loop, "deinit", .{ .err = err });
|
||||||
|
break;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user