medikoo / deferred

Modular and fast Promises implementation for JavaScript
ISC License
364 stars 20 forks source link

Making possible to call deferred() with array #8

Closed yurynix closed 11 years ago

yurynix commented 11 years ago

Hi, Untill now when i had an array of promises, to group them I would just do deferred.apply(deferred, arrayOfPromises).then( ok, fail );

That worked grate for me, untill I had to make some background job that would do some housekeeping on my mongodb collection, at some point it had to update 175K objects, each update was a promise and I wanted to combine them with the above aproach, but then i got from node:

RangeError: Maximum call stack size exceeded

The commited minor change seems to be working with my use case. =) Is there a better approach?

medikoo commented 11 years ago

@yurynix thanks for pull request.

For that, it's best to use deferred.map which you can call without callback argument. See:

// Both resolve with same array result
deferred(one, two, three);
deferred.map([one, two, three]);

Let me know, if that solves issue on your side.

yurynix commented 11 years ago

I haven't realized i can call deferred.map() like that, I've thought it only works as Array.map calling a callback on each element and then returning promise.

Thanks for the clarification, deferred.map works grate for my use case.

Also thank you for the grate library, I'm switching from Q on node, Q was a tremendous performance hit in my app.

medikoo commented 11 years ago

Thanks, I'm glad you like it. I use Deferred in performance intensive, real world projects, it's the best, I know ;-)

Let me know if you have any other issues.