✓
Passing This code compiles and runs correctly.
Code
// The drain arm, with its parameter written. The control for 690_107.
//
// One owned column with no discharger the store can fire, so the store demands a
// `! discharge` arm; the arm binds the column itself (arity picks the payload
// shape), and `cancel(p: item)` hands it over by name. `cancel` returns a value,
// which is exactly why the store cannot fire it unattended — here the arm takes
// the return and prints it.
//
// Everything 690_107 needs is proven sound by this test EXCEPT the one token it
// drops: the written label.
import std/io
import std/store
import app/lib/pend
std/store:new(batch, capacity: 2) { *app/lib/pend:Pending<open!> }
! discharge item |> app/lib/pend:cancel(p: item): n |> std/io:print.ln("cancelled {{ n:d }}")
app/lib/pend:start(): p |> std/store:insert(batch) { p }
| row _ |> _
std/io:print.ln("inserted")
Must contain:
insertedFlows
flow ~new click a branch to expand · @labels scroll to their anchor
new (expr: batch, capacity: 2, source: *app/lib/pend:Pending<open!>)
flow ~start click a branch to expand · @labels scroll to their anchor
start
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "inserted")
Imported Files
// An owned resource with ZERO dischargers a store can fire: *Pending<open!> is
// consumed only by `cancel`, and `cancel` hands back a value. A store tears its
// elements down unattended, where there is nobody to take a return — so the
// column cannot be auto-discharged at any count, and must be DRAINED by a
// `! discharge` arm bolted onto the declaration.
//
// This is the shape koru/curl:Pending has in koru-examples/downloads, where
// `~pub tor cancel { p: *Pending<!open> } -> *Multi<owned!>` returns the batch.
// An i64 return carries the same property without a second obligation.
//
// The contrast is app/lib/tx (690_057/058/097): TWO void dischargers, so the
// store could fire either and refuses because it cannot pick. Here there is
// nothing to pick from.
const std = @import("std");
const Pending = struct { id: i32 };
~pub tor start { } -> *Pending<open!>
~proc start|zig {
const p = std.heap.page_allocator.create(Pending) catch unreachable;
p.* = .{ .id = 3 };
return p;
}
~pub tor cancel { p: *Pending<!open> } -> i64
~proc cancel|zig {
const id = p.id;
std.heap.page_allocator.destroy(p);
return id;
}