Skip to content

Commit 22a93a9

Browse files
committed
add pump message loop calls
1 parent e8866a6 commit 22a93a9

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/app.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator;
44
const log = @import("log.zig");
55
const Loop = @import("runtime/loop.zig").Loop;
66
const http = @import("http/client.zig");
7+
const Platform = @import("runtime/js.zig").Platform;
78

89
const Telemetry = @import("telemetry/telemetry.zig").Telemetry;
910
const Notification = @import("notification.zig").Notification;
@@ -13,6 +14,7 @@ const Notification = @import("notification.zig").Notification;
1314
pub const App = struct {
1415
loop: *Loop,
1516
config: Config,
17+
platform: *const Platform,
1618
allocator: Allocator,
1719
telemetry: Telemetry,
1820
http_client: http.Client,
@@ -28,6 +30,7 @@ pub const App = struct {
2830

2931
pub const Config = struct {
3032
run_mode: RunMode,
33+
platform: *const Platform,
3134
tls_verify_host: bool = true,
3235
http_proxy: ?std.Uri = null,
3336
proxy_type: ?http.ProxyType = null,
@@ -53,6 +56,7 @@ pub const App = struct {
5356
.loop = loop,
5457
.allocator = allocator,
5558
.telemetry = undefined,
59+
.platform = config.platform,
5660
.app_dir_path = app_dir_path,
5761
.notification = notification,
5862
.http_client = try http.Client.init(allocator, loop, .{

src/browser/browser.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const App = @import("../app.zig").App;
2727
const Session = @import("session.zig").Session;
2828
const Notification = @import("../notification.zig").Notification;
2929

30+
const log = @import("../log.zig");
31+
3032
const http = @import("../http/client.zig");
3133

3234
// Browser is an instance of the browser.
@@ -47,7 +49,7 @@ pub const Browser = struct {
4749
pub fn init(app: *App) !Browser {
4850
const allocator = app.allocator;
4951

50-
const env = try Env.init(allocator, .{});
52+
const env = try Env.init(allocator, app.platform, .{});
5153
errdefer env.deinit();
5254

5355
const notification = try Notification.init(allocator, app.notification);
@@ -95,6 +97,9 @@ pub const Browser = struct {
9597
}
9698

9799
pub fn runMicrotasks(self: *const Browser) void {
100+
while (self.env.pumpMessageLoop()) {
101+
log.debug(.browser, "pumpMessageLoop", .{});
102+
}
98103
return self.env.runMicrotasks();
99104
}
100105
};

src/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ fn run(alloc: Allocator) !void {
8383

8484
var app = try App.init(alloc, .{
8585
.run_mode = args.mode,
86+
.platform = &platform,
8687
.http_proxy = args.httpProxy(),
8788
.proxy_type = args.proxyType(),
8889
.proxy_auth = args.proxyAuth(),

src/runtime/js.zig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
156156
return struct {
157157
allocator: Allocator,
158158

159+
platform: *const Platform,
160+
159161
// the global isolate
160162
isolate: v8.Isolate,
161163

@@ -181,7 +183,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
181183

182184
const Opts = struct {};
183185

184-
pub fn init(allocator: Allocator, _: Opts) !*Self {
186+
pub fn init(allocator: Allocator, platform: *const Platform, _: Opts) !*Self {
185187
// var params = v8.initCreateParams();
186188
var params = try allocator.create(v8.CreateParams);
187189
errdefer allocator.destroy(params);
@@ -215,6 +217,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
215217
errdefer allocator.destroy(env);
216218

217219
env.* = .{
220+
.platform = platform,
218221
.isolate = isolate,
219222
.templates = undefined,
220223
.allocator = allocator,
@@ -270,6 +273,10 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
270273
self.isolate.performMicrotasksCheckpoint();
271274
}
272275

276+
pub fn pumpMessageLoop(self: *const Self) bool {
277+
return self.platform.inner.pumpMessageLoop(self.isolate, false);
278+
}
279+
273280
pub fn newExecutionWorld(self: *Self) !ExecutionWorld {
274281
return .{
275282
.env = self,

0 commit comments

Comments
 (0)