Files
mesh-sdk/test/fixtures/stdio-resubscribe.mjs
T
jochen ec80dcfc22 0.1.13: one rule for taking an event, and no handler left by a refused subscribe (hq issue 276)
A handler takes an event by returning and asks for it again by throwing;
any mesh/event answer but an error is taken. Written down in the README
where event handling is, with what follows for a handler: throw only when
the work was not done, and be safe to run twice.

Both SDKs added the handler before asking the runtime and kept it when the
runtime refused, so a module that asks again until it is taken (every Go
consumer does) ran its handler once per attempt for every event. A refused
subscribe now removes its handler; one the Go runtime did not answer in
time is kept, since the runtime may have bound it.
2026-10-06 18:14:58 +02:00

19 lines
620 B
JavaScript

// A launched bundle that asks for its events until the runtime takes the subscription — as a module
// whose first ask may come too early does — and counts how often its one handler is handed an event.
import { on } from "../../dist/events/index.js";
import { serveRegisteredOverStdio } from "../../dist/stdio/index.js";
let handled = 0;
for (;;) {
try {
await on("radarr.download.completed", async () => {
handled++;
process.stderr.write(`handled ${handled}\n`);
});
break;
} catch (err) {
process.stderr.write(`refused: ${err.message}\n`);
}
}
await serveRegisteredOverStdio();