| ... | ... | @@ -22,18 +22,15 @@ pub fn MultiOutStream(comptime OutStreams: type) type { |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | pub fn write(self: *Self, bytes: []const u8) Error!usize { |
| 25 | | if (comptime self.streams.len == 0) return bytes.len; |
| 26 | | |
| 27 | | // only first stream is allowed to do a partial write |
| 28 | | // all subsequent streams do a `.writeAll` |
| 29 | | const bytes_to_write = try self.streams[0].write(bytes); |
| 30 | | const slice_to_write = bytes[0..bytes_to_write]; |
| 31 | | comptime var i = 1; |
| 25 | var batch = std.event.Batch(Error!void, self.streams.len, .auto_async).init(); |
| 26 | comptime var i = 0; |
| 32 | 27 | inline while (i < self.streams.len) : (i += 1) { |
| 33 | 28 | const stream = self.streams[i]; |
| 34 | | try stream.writeAll(slice_to_write); |
| 29 | // TODO: remove ptrCast: https://github.com/ziglang/zig/issues/5258 |
| 30 | batch.add(@ptrCast(anyframe->Error!void, &async stream.writeAll(bytes))); |
| 35 | 31 | } |
| 36 | | return bytes_to_write; |
| 32 | try batch.wait(); |
| 33 | return bytes.len; |
| 37 | 34 | } |
| 38 | 35 | }; |
| 39 | 36 | } |