Bluebird enumerates entire iterable in `.map` and `.forEach` (and probably any other method that accepts iterables)
See original GitHub issue-
What version of bluebird is the issue happening on? 3.4.1
-
What platform and version? (For example Node.js 0.12 or Google Chrome 32) Node.js 6.2.0
-
Did this issue happen with earlier version of bluebird? 3.0 onwards (as earlier versions did not support iterable).
(Write description of your issue here, stack traces from errors and code that reproduces the issue are helpful)
Given the following code:
const bluebird = require('bluebird');
function* test() {
let i = 0;
while (i++ < 10) {
console.log('yield ' + i);
yield i;
}
}
bluebird.each(
test(),
function(i) {
console.log('process ' + i);
return Promise.resolve(i);
}
);
Bluebird will enumerate the generator until finished (which I think internally it must be just converting it to an array).
This causes the following problems:
- You want to iterate over something of infinite value forever
- Your generator yields a promise for an asynchronous operation, which leads to confusion when using concurrency in the map option
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:5
Top Results From Across the Web
Promise.each - Bluebird.js
Given an Iterable (an array, for example), or a promise of an Iterable , iterates serially over all the values in it, executing...
Read more >Enumerate or map through a list with index and value in Dart
There is a asMap method which converts the list to a map where the keys are the index and values are the element...
Read more >The forEach() and map() functions in Dart. - YouTube
In this video we look at the forEach () method (iterate through a List using your own anonymous function) and the map ()...
Read more >Iterable forEach() method in Java with Examples
Whenever we need to traverse over a collection we have to create an Iterator to iterate over the collection and then we can...
Read more >Why and when to use forEach, map, filter, reduce, and find in ...
forEach() , whenever you go to iterate over an array you probably immediately think of a for loop. The .forEach() method is just...
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 Free
Top 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
I do not see the point in supporting iterables if it just drains the whole iterator into an array. The client could already do that itself. I have an iterable that eventually produces hundreds of thousands of values, and I’d like them processed asynchronously and sequentially.
These are features not bugs.
Don’t do that, and what else should Bluebird sensibly do as an alternative to the current behaviour?
Being able to return promises from these helper methods is the entire point of the methods 😃