writeonce/docs/examples/db-actor/main.wo
shoney.arickathil f465ad5751 feat(lang+wo-html): raw text literals, component layer, MVC samples
- lexer: backtick raw text literal — content verbatim, no escape
  processing, common source margin removed at lex time; `${ }` raw and
  `{{ }}` auto-escaping holes
- `{{ e }}` desugars to `esc(${e})` in parser.ml — a Call on the `esc`
  in scope, so types/owner/emit/.wob/VM are untouched
- WO-E004 unterminated raw literal; WO-E005 newline inside "..." —
  closes a hole where a missing quote silently ate the rest of the file
- wo-html: `Component` interface, `render_all`, `Layout`, README
- framework: `ok_html` joins ok_text/ok_json in http/types.wo
- site + shop restructured to one-feature-one-module MVC (view +
  controller per directory, model at the root, bootstrap-only main)
- removed the filler `pad: Int` convention — verified unnecessary for
  plain classes, interface dispatch, containers and actors
- corrected recorded claims: gap #1 blocks neither the build nor the
  layout; a class crosses module lines, only a free fn is scoped
- docs/guides/language-surface.md — the full grammar inventory
- story 37 landed and moved to done/

Gates: oop-accept MET, oop-e2e 116/0, woc-test 556/0, site 11/0,
web-app 46/0, fibers 10/0, db-actor 8/0

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-25 03:58:41 +02:00

61 lines
1.6 KiB
Text

use time
-- db-actor — arc stage 3's acceptance workload: the database is an
-- actor on the owner shard (shard 0); a spawned actor placed on ANY
-- shard reads and writes it through transparent RPC. Before stage 3 a
-- worker-shard insert traps WO_T_DB ("database engine not
-- initialized"); after, this program's output is shard-placement-
-- independent: two writer lines and one exact main line.
@table(name: "notes", index: [tag])
class Note {
tag: Text
val: Int
}
class Job {
n: Int
}
-- Each writer inserts one row, then scans the whole table. Placement is
-- round-robin, so with two writers at default shards one lands off the
-- primary — the RPC path under test.
class Writer {
fn receive(msg: Job) {
insert Note { tag: "w", val: msg.n };
let total = 0;
for x in from n in Note select n {
total = total + x.val;
}
print("writer ${msg.n} sees sum ${total}");
}
}
fn main() -> Int {
let a: actor Job = spawn Writer {};
let b: actor Job = spawn Writer {};
send(a, Job { n: 1 });
send(b, Job { n: 2 });
-- no request/response surface yet (iteration 31): poll until both rows
-- landed, then give the writers' own prints a beat before main returns
-- (main-return reaps every other fiber, mid-print included)
let tries = 0;
let count = 0;
while count < 2 and tries < 200 {
time.sleep(10);
count = 0;
for x in from n in Note select n {
count = count + 1;
}
tries = tries + 1;
}
time.sleep(1000);
count = 0;
let total = 0;
for x in from n in Note select n {
count = count + 1;
total = total + x.val;
}
print("main sees ${count} rows, sum ${total}");
return 0;
}