authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-05-03 18:33:04+10:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-05-03 18:33:04+10:00
log277d088558490ae822826d3713cf961624d56465
tree42b6e31385e547606d0bba52d4760fcff12e2fd7
parent122b992a958d339e9331319db6788e44ee6591b2
signature Commit is signed but in an unrecognized format.

std: use async for MultiOutStream


1 files changed, 6 insertions(+), 9 deletions(-)

lib/std/io/multi_out_stream.zig+6-9
...@@ -22,18 +22,15 @@ pub fn MultiOutStream(comptime OutStreams: type) type {...@@ -22,18 +22,15 @@ pub fn MultiOutStream(comptime OutStreams: type) type {
22 }22 }
2323
24 pub fn write(self: *Self, bytes: []const u8) Error!usize {24 pub fn write(self: *Self, bytes: []const u8) Error!usize {
25 if (comptime self.streams.len == 0) return bytes.len;25 var batch = std.event.Batch(Error!void, self.streams.len, .auto_async).init();
2626 comptime var i = 0;
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;
32 inline while (i < self.streams.len) : (i += 1) {27 inline while (i < self.streams.len) : (i += 1) {
33 const stream = self.streams[i];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}