/// Tables any actor reads without a message (ADR 0073), like Erlang's ETS /// with `read_concurrency` or `persistent_term`: a request reads the latest /// value under a key while one actor keeps it current. /// /// let latest = table.new () /// table.put latest "ada" notebook // from the actor that owns it /// table.get latest "ada" // from any actor: Some(notebook) /// /// A stored value is shared, never copied: `put` makes it shareable once, /// and every `get` hands out the same value. A reader keeps what it read /// after a later `put` or `remove`. Tables live as long as the program; /// replaced and removed values are released when their last reader is /// done with them. import std/process.{type proc} pub opaque type Table { Table(Int) } /// A new, empty table. pub fn new :: -> Table / { Table(new_raw ()) } /// The value under `key`, if any. pub fn get :: table: Table key: String -> Option / { let Table(id) = table get_raw id key } /// Store `value` under `key`, replacing what was there. Only sendable /// values go in: every actor may read them. pub fn put :: table: Table key: String value: v -> () / where Send { let Table(id) = table put_raw id key value } /// Remove `key`, if present. pub fn remove :: table: Table key: String -> () / { let Table(id) = table remove_raw id key } @extern c "tl_table_new" fn new_raw :: -> Int / @extern c "tl_table_get" fn get_raw :: id: Int key: String -> Option / @extern c "tl_table_put" owned fn put_raw :: id: Int key: String value: v -> () / @extern c "tl_table_remove" fn remove_raw :: id: Int key: String -> () /