✓
Passing This code compiles and runs correctly.
Code
~import app/fs
~app/fs:open-two(path1: "test1.txt", path2: "test2.txt")
| opened f |> app/fs:close(file: f.file1) |> app/fs:close(file: f.file2) // Close both files
Imported Files
const std = @import("std");
const File = struct { handle: i32 };
~pub event open-two { path1: []const u8, path2: []const u8 }
| opened { file1: *File<opened!>, file2: *File<opened!> } // TWO obligations!
~proc open-two|zig {
std.debug.print("Opening two files: {s}, {s}\n", .{path1, path2});
const allocator = std.heap.page_allocator;
const f1 = allocator.create(File) catch unreachable;
const f2 = allocator.create(File) catch unreachable;
f1.* = File{ .handle = 42 };
f2.* = File{ .handle = 43 };
return .{ .opened = .{ .file1 = f1, .file2 = f2 } };
}
~pub event close { file: *File<!opened> } // Consumes one obligation
~proc close|zig {
std.debug.print("Closing file\n", .{});
}