Skip to content

Commit 9cc225e

Browse files
refactor(cli): watch daemon
- run watch function as daemon on detached thread
1 parent e2af8fc commit 9cc225e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/cli/cli.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ fn clear(self: *CLI) !void {
244244
STD.debug.print("{s}", .{STYLES.ASCII_STYLES.clear_prompt});
245245
}
246246

247-
// TODO: multi threading
248247
pub fn run(allocator: STD.mem.Allocator) !void {
249248
const self = try allocator.create(CLI);
250249
defer allocator.destroy(self);
@@ -253,11 +252,13 @@ pub fn run(allocator: STD.mem.Allocator) !void {
253252
try iterateExerciseDirectory(self);
254253

255254
try clear(self);
255+
try draw(self);
256256

257-
var watch_thread = try STD.Thread.spawn(.{}, watchFileChanges, .{self});
258-
watch_thread.detach();
257+
try iterateExercises(self);
259258

260-
try draw(self);
259+
const watch_daemon_polling_rate: u64 = 500;
260+
var watch_thread: STD.Thread = try STD.Thread.spawn(.{}, watchFileChanges, .{ self, watch_daemon_polling_rate });
261+
watch_thread.detach();
261262

262263
try userInput(self);
263264
}

0 commit comments

Comments
 (0)