diff --git a/src/lib.zig b/src/lib.zig index 184b958..711b09d 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -78,6 +78,16 @@ fn Channel(comptime T: type) type { return value; } + pub fn peek(self: *const Self) ?T { + const read_idx = self.read.load(.Acquire); + const write_idx = self.write.load(.Acquire); + + if (read_idx == write_idx) return null; + + std.atomic.fence(.Acquire); + return self.buf[self.mask(read_idx)]; + } + pub fn len(self: *const Self) Index { const read_idx = self.read.load(.Acquire); const write_idx = self.write.load(.Acquire);