✓
Passing This code compiles and runs correctly.
Code
~import "$app/fs"
~app.fs:open(path: "test.txt")
| opened f |> app.fs:flush_close(file: f)
Imported Files
const std = @import("std");
const File = struct { handle: i32 };
~pub event open { path: []const u8 }
| opened *File[opened!]
~proc open {
std.debug.print("Opening file: {s}\n", .{path});
const allocator = std.heap.page_allocator;
const f = allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = f };
}
~pub event close { file: *File[!opened] } // Disposal option 1
~proc close {
std.debug.print("Closing file (quick)\n", .{});
}
~pub event flush_close { file: *File[!opened] } // Disposal option 2
~proc flush_close {
std.debug.print("Flushing and closing file\n", .{});
}