If I use the following code NATS listens and processes the first message but not new messages after that. How do I make the sub not close and continuously process messages?
The code below is from the NATS sample code I'm testing with. In can be found here in the fist example under "Publish and Subscribe".
What happens is if I add an async
fn just before the console.log
to process the message then the for loop exists and does not process any more messages. If I don't to this, it continuously processes new messages and the console.log
never prints. How can I make a call inside the loop and not exist?
(async () => {
for await (const m of sub) {
console.log(`[${sub.getProcessed()}]: ${sc.decode(m.data)}`);
}
console.log("subscription closed");
})();