Have message in an array instead of an async iterator
See original GitHub issueI 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:
- Created a year ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 😊
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.