Probably you are using async.js in a wrong way. Do you call the "done
callback" on after every save of the chest? The callback for async.each
received 2 parameters, the item and the done callback.


On Mon, Feb 22, 2016 at 3:55 AM, Duy Nguyen <[email protected]> wrote:

> Hi,
>
> I want to my code work as below:
> 1. save Chest object to db
> 2. Then save all contents belong to this chest to db (have logic to add
> new filed to content before saving)
> 3. Then return response with chest + new contents info
>
> But the real code does not work as I expected, the code is:
>
> chestApi = createChestWithContents{
>>     var chest = req.body;
>>     var contents = req.body.contents;
>>     chest.save(function(err, chest) {
>>            async.each(contents, function(content) {
>>                      content.save()....
>>             }, function(done) {
>>                    return res.status.(200).. ///OK
>>             });
>>     });
>> }
>
>
> When I use postman to test, the method end up without any response
> returned due to asynchronous methods(even when I used async to wait till
> the loop finish), cannot figure out how to do those stuff synchronously.
> --
> Nguyen Hai Duy
> Mobile : 0914 72 1900
> Skype: nguyenhd2107
>
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/CAGOR8-2A8LGnQugzH92quVwEDCiGOBExp7_mq%3DAtjp-LaDt4_Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/nodejs/CAGOR8-2A8LGnQugzH92quVwEDCiGOBExp7_mq%3DAtjp-LaDt4_Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
ema
http://ema.codiceplastico.com <http://blog.codiceplastico.com/ema>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAKxFu7R4ULJxy__sDYjN85X06%3Du2ohbhu53f%3D35%3DnZXdSBP4sw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to