How do I process the results and make sure all async callbacks are finished?
On Sunday, December 9, 2012 1:02:18 AM UTC+7, James Haver II wrote:
>
> Here is the none working format, this is in a function that should return
> results when db is finished.
>
> var results = [];
> dependencies.forEach(function(dependency) {
> db.collection('parts_relations').find(query).toArray(function(err,
> relations) {
> relations.forEach(function(relation) {
> results.push(relation);
> });
> });
> });
>
> I have tried two things without success:
> (this returns before finishing)
> var results = [];
> var counter = 0;
> dependencies.forEach(function(dependency) {
> counter++;
> db.collection('parts_relations').find(query).toArray(function(err,
> relations) {
> relations.forEach(function(relation) {
> results.push(relation);
> });
> if (counter >= dependencies.length) {
> return results;
> }
> });
> });
>
> I also tried wrapping db.collection in a function and passing it to
> async.parallel without luck. Any suggestions?
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.