It works, thank you so much Chris.

On Tue, Feb 23, 2016 at 11:09 PM, Christopher Mina <
christopher.m...@gmail.com> wrote:

> You would simply just call save and then cb().
>
>
> *async.each(contents, function(content, cb) {     content.save(**);*
> *     cb();*
>
>
> *}, function(errors) {    res.status.(200).. ///OK});*
>
>
> On Tuesday, February 23, 2016, Duy Nguyen <nguyenhd2...@gmail.com> wrote:
>
>> Thanks Christopher and Emanuele.
>>
>> I do not want to call cb after saving, mean that I just want to loop via
>> list of contents, then save them, thats all.
>>
>>
>> *async.each(contents, function(content, cb) {
>>  content.save(function(err, resp) {*
>> *         /*DO NOT NEE TO CALL cb HERE*/ cb(err); //lets hope err is
>> null, but if it's not null, the err will get propagated through to the
>> final "errors" param below.*
>>
>>
>>
>> *     });}, function(errors) {    res.status.(200).. ///OK});*
>>
>> Is it possible to apply async without cb param?
>>
>>
>>
>> On Tue, Feb 23, 2016 at 1:44 PM, Christopher Mina <
>> christopher.m...@gmail.com> wrote:
>>
>>> To be clear about Emanuele's response, the async API should look like
>>> this.
>>>
>>> async.each(contents, function(content, cb) {
>>>      content.save(function(err, resp) {
>>>          cb(err); //lets hope err is null, but if it's not null, the err
>>> will get propagated through to the final "errors" param below.
>>>      });
>>> }, function(errors) {
>>>     res.status.(200).. ///OK
>>> });
>>>
>>>
>>> -Chris
>>>
>>> On Monday, February 22, 2016 at 10:01:38 AM UTC-7, Emanuele DelBono
>>> wrote:
>>>>
>>>> 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 <nguyen...@gmail.com>
>>>> 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 nodejs+un...@googlegroups.com.
>>>>> To post to this group, send email to nod...@googlegroups.com.
>>>>> 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 nodejs+unsubscr...@googlegroups.com.
>>> To post to this group, send email to nodejs@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/nodejs/0bb3416a-c622-40ea-a5ab-bfcd93a173fe%40googlegroups.com
>>> <https://groups.google.com/d/msgid/nodejs/0bb3416a-c622-40ea-a5ab-bfcd93a173fe%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> 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 a topic in the
>> Google Groups "nodejs" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/nodejs/SdUS7BE6eRQ/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> nodejs+unsubscr...@googlegroups.com.
>> To post to this group, send email to nodejs@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/nodejs/CAGOR8-34y1CxPPoHDVQ7YsdaS-Mi9MwiW2DEKuYRTP2EH6ZMAQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/nodejs/CAGOR8-34y1CxPPoHDVQ7YsdaS-Mi9MwiW2DEKuYRTP2EH6ZMAQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Christopher Mina
>
> Live Healthy. Work Hard. Be Kind. Gain Success.
>
> --
> 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 nodejs+unsubscr...@googlegroups.com.
> To post to this group, send email to nodejs@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/CAHp1eaOfYOZULSihvQnz_5ov_n%3D5%2Bm2Sw2U0EiSPUS5eb7i9kg%40mail.gmail.com
> <https://groups.google.com/d/msgid/nodejs/CAHp1eaOfYOZULSihvQnz_5ov_n%3D5%2Bm2Sw2U0EiSPUS5eb7i9kg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAGOR8-2-E0jqZWtLjiX1NA%3DejYovKZzD30JtUXZE%2BZ%3DjTm5wgg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to