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.

Bluebird enumerates entire iterable in `.map` and `.forEach` (and probably any other method that accepts iterables)

See original GitHub issue
  1. What version of bluebird is the issue happening on? 3.4.1

  2. What platform and version? (For example Node.js 0.12 or Google Chrome 32) Node.js 6.2.0

  3. 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:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

3reactions
spazmodiuscommented, Jul 13, 2016

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.

1reaction
phpnodecommented, Jun 24, 2016

These are features not bugs.

You want to iterate over something of infinite value forever

Don’t do that, and what else should Bluebird sensibly do as an alternative to the current behaviour?

Your generator yields a promise for an asynchronous operation, which leads to confusion when using concurrency in the map option

Being able to return promises from these helper methods is the entire point of the methods 😃

Read more comments on GitHub >

github_iconTop 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 >

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