diff options
Diffstat (limited to 'test/session.zig')
| -rw-r--r-- | test/session.zig | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/test/session.zig b/test/session.zig index 056966b9..cd04ecb8 100644 --- a/test/session.zig +++ b/test/session.zig @@ -43,6 +43,8 @@ pub const Session = struct { /// meanwhile (a reload). hold_jobs: bool = false, held: std.ArrayList(*pardes.host_io.KindJob) = .empty, + /// Of `held`, those run already (`runJobs`), their answers still held. + ran: usize = 0, /// The files the core asked to watch, watched as a host watches them /// (file_watch.zig, inotify): `filesChanged` wakes them. watch_fd: c_int = -1, @@ -105,6 +107,7 @@ pub const Session = struct { pub fn deinit(s: *Session) void { s.held.deinit(pardesOf(s).gpa); + if (s.hold_jobs) pardes.Kind.drawer = null; if (s.watch_fd >= 0) { pardes.file_watch.unwatchAll(s.watch_fd, &s.watches); _ = std.c.close(s.watch_fd); @@ -308,14 +311,36 @@ pub const Session = struct { return true; } + /// Kinds' jobs and draws held from now on (`hold_jobs`), until + /// `releaseJobs`. + pub fn holdJobs(s: *Session) void { + s.hold_jobs = true; + pardes.Kind.drawer = .{ .ctx = s, .go = struct { + fn go(ctx: ?*anyopaque, j: *pardes.host_io.KindJob) bool { + const ss: *Session = @ptrCast(@alignCast(ctx)); + ss.held.append(pardesOf(ss).gpa, j) catch return false; + return true; + } + }.go }; + } + + /// The jobs held run now, as a worker runs them, their answers held + /// still: what a test does next happens while they are under way. + pub fn runJobs(s: *Session) void { + for (s.held.items[s.ran..]) |j| j.run(); + s.ran = s.held.items.len; + } + /// The jobs held, run now and answered as the host's workers would. pub fn releaseJobs(s: *Session) void { s.hold_jobs = false; - for (s.held.items) |j| { - j.run(); + pardes.Kind.drawer = null; + for (s.held.items, 0..) |j, i| { + if (i >= s.ran) j.run(); j.land(pardesOf(s)); } s.held.clearRetainingCapacity(); + s.ran = 0; s.drain(); } |
