{"id":"9NzSPMQ6dX","url":"https://pastebin.ca/9NzSPMQ6dX","raw_url":"https://raw.anybin.ca/9NzSPMQ6dX","visibility":"public","access":"public","created_at":1780613663637,"expires_at":null,"fetch_limit":null,"fetches_used":0,"reads_remaining":null,"size_bytes":1338,"syntax_hint":"hew","title":null,"filename":null,"change_note":null,"cipher":null,"cipher_meta":null,"parent_id":null,"root_id":"9NzSPMQ6dX","version":1,"owner_id":"06F6D6Y710X9HQV90HF93KWQT8","recipient_id":null,"body":"// Structured concurrency in Hew: a scope owns its child tasks and joins them\n// all before the scope expression returns. Tasks are forked with `fork { ... }`\n// and run on real OS threads; the enclosing `scope { }` is the join boundary.\n//\n// Constraints in this build: spawning happens inside an actor handler (which\n// carries the execution context); each forked function is a zero-argument,\n// unit-returning free function. Nested scopes compose, and an empty\n// `after(d) {}` arms a cancellation deadline on the surrounding scope.\n\nfn fetch_orders() {\n    println(\"fetched orders\");\n}\n\nfn fetch_inventory() {\n    println(\"fetched inventory\");\n}\n\nfn settle() {\n    println(\"reconciled\");\n}\n\nactor _Pipeline {\n    receive fn run() -> i64 {\n        // Outer scope: two siblings fork concurrently and BOTH join here.\n        scope {\n            after(5s) {}\n            fork {\n                fetch_orders();\n            }\n            fork {\n                fetch_inventory();\n            }\n            // Nested scope: its own child joins before the outer scope drains.\n            scope {\n                fork {\n                    settle();\n                }\n            };\n        };\n        0\n    }\n}\n\nfn main() -> i64 {\n    let p = spawn _Pipeline;\n    match await p.run() {\n        Ok(code) => code,\n        Err(_e) => 1,\n    }\n}\n"}