Skip to content

Commit 88d29c9

Browse files
committed
loop: add some comment on reset functions
1 parent f3a9e3d commit 88d29c9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/loop.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ const log = std.log.scoped(.loop);
3333
pub const SingleThreaded = struct {
3434
alloc: std.mem.Allocator, // TODO: unmanaged version ?
3535
io: IO,
36+
37+
// both events_nb are used to track how many callbacks are to be called.
38+
// We use these counters to wait until all the events are finished.
3639
js_events_nb: usize,
3740
zig_events_nb: usize,
41+
3842
cbk_error: bool = false,
3943

4044
// js_ctx_id is incremented each time the loop is reset for JS.
@@ -284,21 +288,36 @@ pub const SingleThreaded = struct {
284288
self.io.cancel_one(*ContextCancel, ctx, cancelCallback, completion, comp_cancel);
285289
}
286290

291+
// cancelAll will cancel all future events.
292+
// The loop will not be usable anymore after cancelAll.
293+
// It is used only during the deinit.
287294
fn cancelAll(self: *Self) void {
288295
self.resetEvents(.js);
289296
self.resetEvents(.zig);
290297
self.io.cancel_all();
291298
}
292299

293300
// Reset all existing JS callbacks.
301+
// The existing events will happen and their memory will be cleanup but the
302+
// corresponding callbacks will not be called.
294303
pub fn resetJS(self: *Self) void {
295304
self.js_ctx_id += 1;
296305
self.cancelled.clearRetainingCapacity();
306+
// We don't call self.resetEvents(.js) intentionnaly.
307+
// Indeed we don't want to prevent the possibility to wait for events.
308+
// The caller may want to wait to have memory correcly cleaned after
309+
// the events happen, even if the callback are ignoreed.
297310
}
298311

299312
// Reset all existing Zig callbacks.
313+
// The existing events will happen and their memory will be cleanup but the
314+
// corresponding callbacks will not be called.
300315
pub fn resetZig(self: *Self) void {
301316
self.zig_ctx_id += 1;
317+
// We don't call self.resetEvents(.zig) intentionnaly.
318+
// Indeed we don't want to prevent the possibility to wait for events.
319+
// The caller may want to wait to have memory correcly cleaned after
320+
// the events happen, even if the callback are ignoreed.
302321
}
303322

304323
// IO callbacks APIs

0 commit comments

Comments
 (0)