From bb8e666d276da9bb7ed5b7b00eb294f0e54fc657 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Wed, 19 Jun 2024 10:05:19 +0900 Subject: [PATCH] aio/coro: rename batch to complete A much less confusing name as it has less overlap with multi --- docs/pages/aio-immediate.mdx | 10 +++++----- examples/aio_static.zig | 2 +- src/aio.zig | 6 +++--- src/coro.zig | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/pages/aio-immediate.mdx b/docs/pages/aio-immediate.mdx index 462aa3a7..d1d8d15b 100644 --- a/docs/pages/aio-immediate.mdx +++ b/docs/pages/aio-immediate.mdx @@ -37,12 +37,12 @@ try aio.multi(.{ The `.link_next` field of operation can be used to link the operation to the next operation. When linking operations, the next operation won't start until this operation is complete. -#### Using batch +#### Using complete -Batch is similar to multi, but it will not return `error.SomeOperationFailed` in case any of the operations fail. -Instead batch returns `aio.CompletionResult` which contains the number of operations that was completed, and number of +Complete is similar to multi, but it will not return `error.SomeOperationFailed` in case any of the operations fail. +Instead complete returns `aio.CompletionResult` which contains the number of operations that was completed, and number of errors that occured. To find out which operations failed, errors have to be stored somewhere by setting the `.out_error` -field of the operation. The batch call may still fail in implementation defined ways, such as running out of system resources. +field of the operation. The complete call may still fail in implementation defined ways, such as running out of system resources. ```zig var my_buffer: [1024]u8 = undefined; @@ -50,7 +50,7 @@ var my_len: usize = undefined; var write_error: std.posix.WriteError = undefined; var read_error: std.posix.ReadError = undefined; -const res = try aio.batch(.{ +const res = try aio.complete(.{ aio.Write{.file = f, .buffer = "contents", .out_error = &write_error, .link_next = true}, aio.Read{.file = f, .buffer = &my_buffer, .out_error = &read_error, .out_read = &my_len}, }); diff --git a/examples/aio_static.zig b/examples/aio_static.zig index 17b9b1bd..24fe3f94 100644 --- a/examples/aio_static.zig +++ b/examples/aio_static.zig @@ -13,7 +13,7 @@ pub fn main() !void { var buf2: [4096]u8 = undefined; var len2: usize = 0; - const ret = try aio.batch(.{ + const ret = try aio.complete(.{ aio.Read{ .file = f, .buffer = &buf, diff --git a/src/aio.zig b/src/aio.zig index b3397f21..1be91b17 100644 --- a/src/aio.zig +++ b/src/aio.zig @@ -76,7 +76,7 @@ pub const Dynamic = struct { /// Completes a list of operations immediately, blocks until complete /// For error handling you must check the `out_error` field in the operation -pub inline fn batch(operations: anytype) ImmediateError!CompletionResult { +pub inline fn complete(operations: anytype) ImmediateError!CompletionResult { const ti = @typeInfo(@TypeOf(operations)); if (comptime ti == .Struct and ti.Struct.is_tuple) { return IO.immediate(operations.len, &struct { ops: @TypeOf(operations) }{ .ops = operations }); @@ -90,7 +90,7 @@ pub inline fn batch(operations: anytype) ImmediateError!CompletionResult { /// Completes a list of operations immediately, blocks until complete /// Returns `error.SomeOperationFailed` if any operation failed pub inline fn multi(operations: anytype) (ImmediateError || error{SomeOperationFailed})!void { - const res = try batch(operations); + const res = try complete(operations); if (res.num_errors > 0) return error.SomeOperationFailed; } @@ -99,7 +99,7 @@ pub inline fn single(operation: anytype) (ImmediateError || OperationError)!void var op: @TypeOf(operation) = operation; var err: @TypeOf(operation).Error = error.Success; op.out_error = &err; - _ = try batch(.{op}); + _ = try complete(.{op}); if (err != error.Success) return err; } diff --git a/src/coro.zig b/src/coro.zig index 13765e2e..35723e05 100644 --- a/src/coro.zig +++ b/src/coro.zig @@ -39,7 +39,7 @@ pub const io = struct { /// The IO operations can be cancelled by calling `wakeup` /// For error handling you must check the `out_error` field in the operation /// Returns the number of errors occured, 0 if there were no errors - pub inline fn batch(operations: anytype) aio.QueueError!u16 { + pub inline fn complete(operations: anytype) aio.QueueError!u16 { if (Fiber.current()) |fiber| { var task: *Scheduler.TaskState = @ptrFromInt(fiber.getUserDataPtr().*); @@ -86,7 +86,7 @@ pub const io = struct { /// The IO operations can be cancelled by calling `wakeupFromIo`, or doing `aio.Cancel` /// Returns `error.SomeOperationFailed` if any operation failed pub inline fn multi(operations: anytype) (aio.QueueError || error{SomeOperationFailed})!void { - if (try batch(operations) > 0) return error.SomeOperationFailed; + if (try complete(operations) > 0) return error.SomeOperationFailed; } /// Completes a single operation immediately, blocks the coroutine until complete @@ -95,7 +95,7 @@ pub const io = struct { var op: @TypeOf(operation) = operation; var err: @TypeOf(operation).Error = error.Success; op.out_error = &err; - _ = try batch(.{op}); + _ = try complete(.{op}); if (err != error.Success) return err; } };