Files
mesh-sdk/test/fixtures/stdio-long-running.mjs
T
jochen 1f936dc4a6 A launched bundle subscribes and asks through its runtime, and its code may do so while being imported (hq ADR 0198)
The stdio channel is the bundle's bus: subscribe asks the runtime (mesh/subscribe), which binds the
module's durable consumer and hands each event over as mesh/event — answered once every matching
handler has taken it, as an error when one failed so the runtime does not acknowledge it; request
asks the runtime (mesh/ask). The session starts as the stdio module loads when the runtime launched
the process, because a handler module subscribes at import, before the launcher says what it
serves; initialize and tools/list are answered once it has. topicMatches as the runtime's. 0.1.6.
2026-10-03 22:23:16 +02:00

16 lines
826 B
JavaScript

// A launched bundle whose module code runs long (novox/hq ADR 0198): it subscribes as it is imported,
// before it says what it serves — exactly as a handler module's index does — and one tool asks the bus.
import { on } from "../../dist/events/index.js";
import { broker } from "../../dist/messaging/index.js";
import { registerModuleTools } from "../../dist/tools/index.js";
import { serveRegisteredOverStdio } from "../../dist/stdio/index.js";
await on("alpha.happened", async (e) => {
process.stderr.write(`handled ${e.type} ${JSON.stringify(e.body)}\n`);
if (e.body && e.body.fail) throw new Error("not this one");
});
registerModuleTools("watcher", () => [
{ name: "relay", description: "asks beta", input: {}, run: async () => broker().request("beta.one", { x: 1 }) },
]);
await serveRegisteredOverStdio();