Skip to content

Commit

Permalink
Fix race condition trying to track last argument
Browse files Browse the repository at this point in the history
The Previewer last_arg has a race condition. This would be better solved
with a queue. But for now, it is good enough to just spawn a new child
on each selection change.
  • Loading branch information
natecraddock committed Oct 2, 2024
1 parent 3db9363 commit 6a0d902
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/tui/Previewer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ fn threadLoop(previewer: *Previewer, loop: *vaxis.Loop(Event)) !void {
while (true) {
previewer.semaphore.wait();

// If the arg is already being previewed we don't need to do any work
if (mem.eql(u8, previewer.arg, previewer.last_arg)) {
continue;
}

const command = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ previewer.cmd_parts[0], previewer.arg, previewer.cmd_parts[1] });

var child = Child.init(&.{ previewer.shell, "-c", command }, allocator);
Expand Down Expand Up @@ -99,7 +94,6 @@ fn threadLoop(previewer: *Previewer, loop: *vaxis.Loop(Event)) !void {
previewer.output = "Invalid utf8";
}

previewer.last_arg = try allocator.dupe(u8, previewer.arg);
loop.postEvent(.preview_ready);
}
}
Expand Down

0 comments on commit 6a0d902

Please sign in to comment.