add pump message loop calls

This commit is contained in:
Pierre Tachoire
2025-06-30 15:03:52 -07:00
parent e8866a6431
commit 22a93a9c39
4 changed files with 19 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator;
const log = @import("log.zig"); const log = @import("log.zig");
const Loop = @import("runtime/loop.zig").Loop; const Loop = @import("runtime/loop.zig").Loop;
const http = @import("http/client.zig"); const http = @import("http/client.zig");
const Platform = @import("runtime/js.zig").Platform;
const Telemetry = @import("telemetry/telemetry.zig").Telemetry; const Telemetry = @import("telemetry/telemetry.zig").Telemetry;
const Notification = @import("notification.zig").Notification; const Notification = @import("notification.zig").Notification;
@@ -13,6 +14,7 @@ const Notification = @import("notification.zig").Notification;
pub const App = struct { pub const App = struct {
loop: *Loop, loop: *Loop,
config: Config, config: Config,
platform: *const Platform,
allocator: Allocator, allocator: Allocator,
telemetry: Telemetry, telemetry: Telemetry,
http_client: http.Client, http_client: http.Client,
@@ -28,6 +30,7 @@ pub const App = struct {
pub const Config = struct { pub const Config = struct {
run_mode: RunMode, run_mode: RunMode,
platform: *const Platform,
tls_verify_host: bool = true, tls_verify_host: bool = true,
http_proxy: ?std.Uri = null, http_proxy: ?std.Uri = null,
proxy_type: ?http.ProxyType = null, proxy_type: ?http.ProxyType = null,
@@ -53,6 +56,7 @@ pub const App = struct {
.loop = loop, .loop = loop,
.allocator = allocator, .allocator = allocator,
.telemetry = undefined, .telemetry = undefined,
.platform = config.platform,
.app_dir_path = app_dir_path, .app_dir_path = app_dir_path,
.notification = notification, .notification = notification,
.http_client = try http.Client.init(allocator, loop, .{ .http_client = try http.Client.init(allocator, loop, .{

View File

@@ -27,6 +27,8 @@ const App = @import("../app.zig").App;
const Session = @import("session.zig").Session; const Session = @import("session.zig").Session;
const Notification = @import("../notification.zig").Notification; const Notification = @import("../notification.zig").Notification;
const log = @import("../log.zig");
const http = @import("../http/client.zig"); const http = @import("../http/client.zig");
// Browser is an instance of the browser. // Browser is an instance of the browser.
@@ -47,7 +49,7 @@ pub const Browser = struct {
pub fn init(app: *App) !Browser { pub fn init(app: *App) !Browser {
const allocator = app.allocator; const allocator = app.allocator;
const env = try Env.init(allocator, .{}); const env = try Env.init(allocator, app.platform, .{});
errdefer env.deinit(); errdefer env.deinit();
const notification = try Notification.init(allocator, app.notification); const notification = try Notification.init(allocator, app.notification);
@@ -95,6 +97,9 @@ pub const Browser = struct {
} }
pub fn runMicrotasks(self: *const Browser) void { pub fn runMicrotasks(self: *const Browser) void {
while (self.env.pumpMessageLoop()) {
log.debug(.browser, "pumpMessageLoop", .{});
}
return self.env.runMicrotasks(); return self.env.runMicrotasks();
} }
}; };

View File

@@ -83,6 +83,7 @@ fn run(alloc: Allocator) !void {
var app = try App.init(alloc, .{ var app = try App.init(alloc, .{
.run_mode = args.mode, .run_mode = args.mode,
.platform = &platform,
.http_proxy = args.httpProxy(), .http_proxy = args.httpProxy(),
.proxy_type = args.proxyType(), .proxy_type = args.proxyType(),
.proxy_auth = args.proxyAuth(), .proxy_auth = args.proxyAuth(),

View File

@@ -156,6 +156,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
return struct { return struct {
allocator: Allocator, allocator: Allocator,
platform: *const Platform,
// the global isolate // the global isolate
isolate: v8.Isolate, isolate: v8.Isolate,
@@ -181,7 +183,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
const Opts = struct {}; const Opts = struct {};
pub fn init(allocator: Allocator, _: Opts) !*Self { pub fn init(allocator: Allocator, platform: *const Platform, _: Opts) !*Self {
// var params = v8.initCreateParams(); // var params = v8.initCreateParams();
var params = try allocator.create(v8.CreateParams); var params = try allocator.create(v8.CreateParams);
errdefer allocator.destroy(params); errdefer allocator.destroy(params);
@@ -215,6 +217,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
errdefer allocator.destroy(env); errdefer allocator.destroy(env);
env.* = .{ env.* = .{
.platform = platform,
.isolate = isolate, .isolate = isolate,
.templates = undefined, .templates = undefined,
.allocator = allocator, .allocator = allocator,
@@ -270,6 +273,10 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
self.isolate.performMicrotasksCheckpoint(); self.isolate.performMicrotasksCheckpoint();
} }
pub fn pumpMessageLoop(self: *const Self) bool {
return self.platform.inner.pumpMessageLoop(self.isolate, false);
}
pub fn newExecutionWorld(self: *Self) !ExecutionWorld { pub fn newExecutionWorld(self: *Self) !ExecutionWorld {
return .{ return .{
.env = self, .env = self,