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.
19 lines
620 B
JavaScript
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();
|