multiple cleanup paths

✓ Passing This code compiles and runs correctly.

Code

// Test 519: Multiple cleanup paths
// Tests that multiple disposal events can coexist
//
// Key points:
// - fs module provides TWO disposal events: close and flush_close
// - Both accept *File[!opened] (both consume obligation)
// - User explicitly chooses flush_close
// - Obligation is satisfied regardless of which path is chosen

~import "$app/fs"

~app.fs:open(path: "test.txt")
| opened f |> app.fs:flush_close(file: f.file)  // Explicit choice of cleanup path
    | flushed |> _
input.kz

Imported Files

const std = @import("std");
const File = struct { handle: i32 };

~pub event open { path: []const u8 }
| opened { file: *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 = .{ .file = f } };
}

~pub event close { file: *File[!opened] }  // Disposal option 1
| closed {}

~proc close {
    std.debug.print("Closing file (quick)\n", .{});
    return .{ .closed = .{} };
}

~pub event flush_close { file: *File[!opened] }  // Disposal option 2
| flushed {}

~proc flush_close {
    std.debug.print("Flushing and closing file\n", .{});
    return .{ .flushed = .{} };
}
fs.kz