add runIdleTasks

This commit is contained in:
Pierre Tachoire
2025-06-30 18:50:04 -07:00
parent 22a93a9c39
commit 3c0143af92
3 changed files with 13 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ const Notification = @import("notification.zig").Notification;
pub const App = struct {
loop: *Loop,
config: Config,
platform: *const Platform,
platform: ?*const Platform,
allocator: Allocator,
telemetry: Telemetry,
http_client: http.Client,
@@ -30,7 +30,7 @@ pub const App = struct {
pub const Config = struct {
run_mode: RunMode,
platform: *const Platform,
platform: ?*const Platform = null,
tls_verify_host: bool = true,
http_proxy: ?std.Uri = null,
proxy_type: ?http.ProxyType = null,

View File

@@ -97,10 +97,11 @@ pub const Browser = struct {
}
pub fn runMicrotasks(self: *const Browser) void {
self.env.runMicrotasks();
while (self.env.pumpMessageLoop()) {
log.debug(.browser, "pumpMessageLoop", .{});
}
return self.env.runMicrotasks();
self.env.runIdleTasks();
}
};

View File

@@ -156,7 +156,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
return struct {
allocator: Allocator,
platform: *const Platform,
platform: ?*const Platform,
// the global isolate
isolate: v8.Isolate,
@@ -183,7 +183,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
const Opts = struct {};
pub fn init(allocator: Allocator, platform: *const Platform, _: Opts) !*Self {
pub fn init(allocator: Allocator, platform: ?*const Platform, _: Opts) !*Self {
// var params = v8.initCreateParams();
var params = try allocator.create(v8.CreateParams);
errdefer allocator.destroy(params);
@@ -274,7 +274,13 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
}
pub fn pumpMessageLoop(self: *const Self) bool {
return self.platform.inner.pumpMessageLoop(self.isolate, false);
if (self.platform == null) return false;
return self.platform.?.inner.pumpMessageLoop(self.isolate, false);
}
pub fn runIdleTasks(self: *const Self) void {
if (self.platform == null) return;
return self.platform.?.inner.runIdleTasks(self.isolate, 1);
}
pub fn newExecutionWorld(self: *Self) !ExecutionWorld {