Closed andreashuber69 closed 1 year ago
Sorry, I meant to open this in https://github.com/alexbosworth/lightning, but I guess it applies to this project too.
i think this is a node.js question? if you have open listeners node.js wouldn't exit right?
i think this is a node.js question? if you have open listeners node.js wouldn't exit right?
I would agree with you if the behavior was equivalent for subscribeToBlocks
and subscribeToForwards
. It clearly isn't, everything works as expected for the former but not for the latter.
Also, note that I remove the handler on the last line emitter.off(eventName, handler);
Did you try using emitter.removeAllListeners() ?
Did you try using emitter.removeAllListeners() ?
Just tried that, the result is the same. Works with blocks, doesn't work with forwards. Here's the CTRL-C, CTRL-V of the code:
import { subscribeToForwards } from "lightning";
import { connectLnd } from "./test/connectLnd.js";
const eventName = "forward";
const waitTime = 5000;
const authenticatedLnd = await connectLnd();
const emitter = subscribeToForwards(authenticatedLnd);
const handler = (e: unknown) => console.log(e);
emitter.on(eventName, handler);
console.log(`Waiting for ${waitTime / 1000} seconds...`);
await new Promise((resolve) => setTimeout(resolve, waitTime));
console.log("Shutting down...");
emitter.removeAllListeners();
Hmm ok I guess it has an issue, can take a look
Should be fixed now, can you try on the latest version?
import { subscribeToForwards } from "lightning"; import { connectLnd } from "./test/connectLnd.js";
const eventName = "forward"; const waitTime = 5000;
const authenticatedLnd = await connectLnd(); const emitter = subscribeToForwards(authenticatedLnd); const handler = (e: unknown) => console.log(e);
emitter.on(eventName, handler); console.log(
Waiting for ${waitTime / 1000} seconds...
); await new Promise((resolve) => setTimeout(resolve, waitTime)); console.log("Shutting down..."); emitter.removeAllListeners();
I've tried with subscribeToForwards
, subscribeToPayments
, subscribeToChannels
and they all now work as expected. Thank you!
Playing with lightning 9.8.1, the above code works as expected. That is, I get the following output and the process ends.
However, when I use
subscribeToForwards
instead ofsubscribeToBlocks
and seteventName
toforward
instead ofblock
, the process hangs after loggingShutting down...
. Why?