--- in2.zig 2020-01-28 21:57:31.964205087 -0500 +++ test2.zig 2020-01-28 22:24:10.761897754 -0500 @@ -33,22 +33,29 @@ }; } +pub const io_mode = .evented; + pub fn main() !void { const allocator = &std.heap.ArenaAllocator.init(std.heap.page_allocator).allocator; const args = try std.process.argsAlloc(allocator); const cwd = std.fs.cwd(); + var list = std.ArrayList(anyframe->anyerror!void).init(allocator); for (args[1..]) |arg| { const file = cwd.openFile(arg, .{}) catch |err| { std.debug.warn("Unable to open file: {}\n", .{@errorName(err)}); return err; }; - defer file.close(); - try wc_file(file); + const frame = try allocator.create(@Frame(wc_file)); + frame.* = async wc_file(file); + try list.append(frame); + } + for (list.toSlice()) |frame| { + try await frame; } } -fn wc_file(file: std.fs.File) !void { +fn wc_file(file: std.fs.File) anyerror!void { var file_unbuf = file.inStream(); const in = &std.io.BufferedInStream(@TypeOf(file_unbuf).Error).init(&file_unbuf.stream).stream; var o = Output{