diff --git a/lib/std/Io.zig b/lib/std/Io.zig index 7f945c8994be6556ae7c96b83457db7047274dea..9332633c8c854d3158ca439c541a4b0786448739 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -500,8 +500,8 @@ pub const Batch = struct { /// Returns the index that will be returned by `next` after the operation completes. /// Asserts that no more than `storage.len` operations are active at a time. pub fn add(batch: *Batch, operation: Operation) u32 { - const index = batch.unused.next; - batch.addAt(index.toIndex(), operation); + const index = batch.unused.head.toIndex(); + batch.addAt(index, operation); return index; } diff --git a/lib/std/Io/test.zig b/lib/std/Io/test.zig index 62ad3c2ec8fc4b182b2071363fd13729c3c86043..73931f9ea9ba04facc1662da3e5ef4d1743b1bdf 100644 --- a/lib/std/Io/test.zig +++ b/lib/std/Io/test.zig @@ -692,14 +692,15 @@ test "read from a file using Batch.awaitAsync API" { var storage: [2]Io.Operation.Storage = undefined; var batch: Io.Batch = .init(&storage); - batch.addAt(0, .{ .file_read_streaming = .{ + // Tests add API because this provides coverage for both add and addAt. + try testing.expectEqual(0, batch.add(.{ .file_read_streaming = .{ .file = eyes_file, .data = &.{&eyes_buf}, - } }); - batch.addAt(1, .{ .file_read_streaming = .{ + } })); + try testing.expectEqual(1, batch.add(.{ .file_read_streaming = .{ .file = saviour_file, .data = &.{&saviour_buf}, - } }); + } })); // This API is supposed to *always* work even if the target has no // concurrency primitives available.