@@ -39,9 +39,9 @@ fn report(comptime fmt: []const u8, args: anytype) void {
3939// I/O APIs based on async/await might be added in the future.
4040pub const SingleThreaded = struct {
4141 alloc : std.mem.Allocator , // TODO: unmanaged version ?
42- io : * IO ,
43- js_events_nb : * usize ,
44- zig_events_nb : * usize ,
42+ io : IO ,
43+ js_events_nb : usize ,
44+ zig_events_nb : usize ,
4545 cbk_error : bool = false ,
4646
4747 // js_ctx_id is incremented each time the loop is reset for JS.
@@ -64,21 +64,11 @@ pub const SingleThreaded = struct {
6464 pub const SendError = IO .SendError ;
6565
6666 pub fn init (alloc : std.mem.Allocator ) ! Self {
67- const io = try alloc .create (IO );
68- errdefer alloc .destroy (io );
69-
70- io .* = try IO .init (32 , 0 );
71-
72- const js_events_nb = try alloc .create (usize );
73- js_events_nb .* = 0 ;
74- const zig_events_nb = try alloc .create (usize );
75- zig_events_nb .* = 0 ;
76-
7767 return Self {
7868 .alloc = alloc ,
79- .io = io ,
80- .js_events_nb = js_events_nb ,
81- .zig_events_nb = zig_events_nb ,
69+ .io = try IO . init ( 32 , 0 ) ,
70+ .js_events_nb = 0 ,
71+ .zig_events_nb = 0 ,
8272 };
8373 }
8474
@@ -91,13 +81,8 @@ pub const SingleThreaded = struct {
9181 break ;
9282 };
9383 }
94-
9584 self .cancelAll ();
96-
9785 self .io .deinit ();
98- self .alloc .destroy (self .io );
99- self .alloc .destroy (self .js_events_nb );
100- self .alloc .destroy (self .zig_events_nb );
10186 }
10287
10388 // Retrieve all registred I/O events completed by OS kernel,
@@ -121,10 +106,10 @@ pub const SingleThreaded = struct {
121106
122107 const Event = enum { js , zig };
123108
124- fn eventsPtr (self : * const Self , event : Event ) * usize {
109+ fn eventsPtr (self : * Self , event : Event ) * usize {
125110 return switch (event ) {
126- .zig = > self .zig_events_nb ,
127- .js = > self .js_events_nb ,
111+ .zig = > & self .zig_events_nb ,
112+ .js = > & self .js_events_nb ,
128113 };
129114 }
130115
0 commit comments