question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have message in an array instead of an async iterator

See original GitHub issue

I use NATS with Jetstream and pull consumers. As documentation specifies, I use this method to get messages:

const jetstreamClient = natsConnection.jetstream()
const myConsumer = await jetstreamClient.pullSubscribe('myStream.mySubject', myOptions)
myConsumer.pull({ batch: limit })
for await (const message of myConsumer) {
    // Do something
}

Anyway, for some reasons, it would useful to me to have an array instead of an async iterator. I image something like that:

const jetstreamClient = natsConnection.jetstream()
const myConsumer = await jetstreamClient.pullSubscribe('myStream.mySubject', myOptions)
const messages = await myConsumer.pull({ batch: limit })
for (const message of messages) {
    // Do something
}

Is there a a way to achieve that?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
matteodisabatinocommented, Jul 21, 2022

Hi @aricart, sorry for have been extremely late… I forgot to let you know 😅

Anyway, your suggestions were perfect: i totally solved my problem. Thank you so much 😊

0reactions
matteodisabatinocommented, Jun 3, 2022

queue groups are not necessary on pull consumers

This is wonderful! I didn’t know that, I’ll make some tests and I’ll let you know (if all works, maybe, you can add an example on the readme)

Thanks for your clarity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript async iterators - Node.js Design Patterns
This syntax provides a very easy way to iterate over collections, such as arrays, string, sets, and maps. If you have never seen...
Read more >
for await...of - JavaScript - MDN Web Docs
The for await...of statement creates a loop iterating over async iterable objects as well as sync iterables. This statement can only be used ......
Read more >
Cross-window async iterators using Comlink - Scott Logic Blog
I assumed when it was given an array, it just knew how to iterate over it. However, it turns out that the iteration...
Read more >
Using async/await with a forEach loop - Stack Overflow
This answer is wrong. files. map() returns an array of promises, not an asynchronous iterator, for which for await was made! It will...
Read more >
Dealing with Promises In an Array with async/await
Promise.all accepts an array of promises and returns a new promise that resolves only when all of the promises in the array have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found