diff options
| author | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2022-11-20 20:16:40 -0800 |
|---|---|---|
| committer | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2022-11-20 20:16:40 -0800 |
| commit | a15afa8211e30b2215b0be5fce700481fd37a729 (patch) | |
| tree | 259fdb11a626815c3219629b20fbc4301ce73dfe /src/termio/Thread.zig | |
| parent | d213c1a939710a26672e4711bbb1337610f32a37 (diff) | |
do not block channel send while draining channel
Diffstat (limited to 'src/termio/Thread.zig')
| -rw-r--r-- | src/termio/Thread.zig | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/termio/Thread.zig b/src/termio/Thread.zig index 7c75d9603..78968de48 100644 --- a/src/termio/Thread.zig +++ b/src/termio/Thread.zig @@ -162,24 +162,19 @@ fn drainMailbox(self: *Thread) !void { // expectation is that all our message handlers will be non-blocking // ENOUGH to not mess up throughput on producers. var redraw: bool = false; - { - var drain = self.mailbox.drain(); - defer drain.deinit(); - - while (drain.next()) |message| { - // If we have a message we always redraw - redraw = true; - - log.debug("mailbox message={}", .{message}); - switch (message) { - .resize => |v| try self.impl.resize(v.grid_size, v.screen_size, v.padding), - .write_small => |v| try self.impl.queueWrite(v.data[0..v.len]), - .write_stable => |v| try self.impl.queueWrite(v), - .write_alloc => |v| { - defer v.alloc.free(v.data); - try self.impl.queueWrite(v.data); - }, - } + while (self.mailbox.pop()) |message| { + // If we have a message we always redraw + redraw = true; + + log.debug("mailbox message={}", .{message}); + switch (message) { + .resize => |v| try self.impl.resize(v.grid_size, v.screen_size, v.padding), + .write_small => |v| try self.impl.queueWrite(v.data[0..v.len]), + .write_stable => |v| try self.impl.queueWrite(v), + .write_alloc => |v| { + defer v.alloc.free(v.data); + try self.impl.queueWrite(v.data); + }, } } |
