A module's state through the runtime, in TypeScript and Go (novox/hq ADR 0201)
state(name) / stdio.State(name): get, put, delete, keys and watch over the runtime's mesh/state verbs. A watch's handler is registered under the id it is asked with, so its current values — which arrive before the watch is answered — and its changes reach it and no other watch.
This commit is contained in:
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// A launched bundle that keeps state through its runtime (novox/hq ADR 0201): it watches its servers as
|
||||
// it is imported, before it says what it serves, and its tools write, read and list them.
|
||||
import { state } from "../../dist/state/index.js";
|
||||
import { registerModuleTools } from "../../dist/tools/index.js";
|
||||
import { serveRegisteredOverStdio } from "../../dist/stdio/index.js";
|
||||
|
||||
const servers = state("servers");
|
||||
await servers.watch((c) => {
|
||||
process.stderr.write(`${c.current ? "was" : "now"} ${c.op} ${c.key} ${JSON.stringify(c.value ?? null)}\n`);
|
||||
if (c.value && c.value.fail) throw new Error("not this one");
|
||||
});
|
||||
process.stderr.write("watching\n");
|
||||
registerModuleTools("keeper", () => [
|
||||
{ name: "remember", description: "put", input: {}, run: async (a) => servers.put(a.key, a.value) },
|
||||
{ name: "recall", description: "get", input: {}, run: async (a) => servers.get(a.key) },
|
||||
{ name: "list", description: "keys", input: {}, run: async () => state("licence-manager.bindings").keys() },
|
||||
]);
|
||||
await serveRegisteredOverStdio();
|
||||
Reference in New Issue
Block a user