Skip to content

Commit 3c0143a

Browse files
committed
add runIdleTasks
1 parent 22a93a9 commit 3c0143a

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/app.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Notification = @import("notification.zig").Notification;
1414
pub const App = struct {
1515
loop: *Loop,
1616
config: Config,
17-
platform: *const Platform,
17+
platform: ?*const Platform,
1818
allocator: Allocator,
1919
telemetry: Telemetry,
2020
http_client: http.Client,
@@ -30,7 +30,7 @@ pub const App = struct {
3030

3131
pub const Config = struct {
3232
run_mode: RunMode,
33-
platform: *const Platform,
33+
platform: ?*const Platform = null,
3434
tls_verify_host: bool = true,
3535
http_proxy: ?std.Uri = null,
3636
proxy_type: ?http.ProxyType = null,

src/browser/browser.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ pub const Browser = struct {
9797
}
9898

9999
pub fn runMicrotasks(self: *const Browser) void {
100+
self.env.runMicrotasks();
100101
while (self.env.pumpMessageLoop()) {
101102
log.debug(.browser, "pumpMessageLoop", .{});
102103
}
103-
return self.env.runMicrotasks();
104+
self.env.runIdleTasks();
104105
}
105106
};
106107

src/runtime/js.zig

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

159-
platform: *const Platform,
159+
platform: ?*const Platform,
160160

161161
// the global isolate
162162
isolate: v8.Isolate,
@@ -183,7 +183,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
183183

184184
const Opts = struct {};
185185

186-
pub fn init(allocator: Allocator, platform: *const Platform, _: Opts) !*Self {
186+
pub fn init(allocator: Allocator, platform: ?*const Platform, _: Opts) !*Self {
187187
// var params = v8.initCreateParams();
188188
var params = try allocator.create(v8.CreateParams);
189189
errdefer allocator.destroy(params);
@@ -274,7 +274,13 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
274274
}
275275

276276
pub fn pumpMessageLoop(self: *const Self) bool {
277-
return self.platform.inner.pumpMessageLoop(self.isolate, false);
277+
if (self.platform == null) return false;
278+
return self.platform.?.inner.pumpMessageLoop(self.isolate, false);
279+
}
280+
281+
pub fn runIdleTasks(self: *const Self) void {
282+
if (self.platform == null) return;
283+
return self.platform.?.inner.runIdleTasks(self.isolate, 1);
278284
}
279285

280286
pub fn newExecutionWorld(self: *Self) !ExecutionWorld {

0 commit comments

Comments
 (0)