Skip to content

Commit fd49011

Browse files
committed
quick experiment for re-using an isolate
1 parent cc82b1a commit fd49011

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/app.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const std = @import("std");
22
const Allocator = std.mem.Allocator;
33

4+
const Env = @import("browser/env.zig").Env;
45
const Loop = @import("runtime/loop.zig").Loop;
56
const HttpClient = @import("http/client.zig").Client;
67
const Telemetry = @import("telemetry/telemetry.zig").Telemetry;
@@ -11,6 +12,7 @@ const log = std.log.scoped(.app);
1112
// Container for global state / objects that various parts of the system
1213
// might need.
1314
pub const App = struct {
15+
env: *Env,
1416
loop: *Loop,
1517
config: Config,
1618
allocator: Allocator,
@@ -47,7 +49,11 @@ pub const App = struct {
4749

4850
const app_dir_path = getAndMakeAppDir(allocator);
4951

52+
const env = try Env.init(allocator, .{});
53+
errdefer env.deinit();
54+
5055
app.* = .{
56+
.env = env,
5157
.loop = loop,
5258
.allocator = allocator,
5359
.telemetry = undefined,
@@ -75,6 +81,7 @@ pub const App = struct {
7581
allocator.destroy(self.loop);
7682
self.http_client.deinit();
7783
self.notification.deinit();
84+
self.env.deinit();
7885
allocator.destroy(self);
7986
}
8087
};

src/browser/browser.zig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ pub const Browser = struct {
4545
pub fn init(app: *App) !Browser {
4646
const allocator = app.allocator;
4747

48-
const env = try Env.init(allocator, .{});
49-
errdefer env.deinit();
5048

5149
const notification = try Notification.init(allocator, app.notification);
5250
errdefer notification.deinit();
5351

5452
return .{
5553
.app = app,
56-
.env = env,
54+
.env = app.env,
5755
.session = null,
5856
.allocator = allocator,
5957
.notification = notification,
@@ -66,7 +64,6 @@ pub const Browser = struct {
6664

6765
pub fn deinit(self: *Browser) void {
6866
self.closeSession();
69-
self.env.deinit();
7067
self.page_arena.deinit();
7168
self.session_arena.deinit();
7269
self.transfer_arena.deinit();

0 commit comments

Comments
 (0)