On Tue, Apr 17, 2012 at 10:53 AM, Mario Konschake
<[email protected]> wrote:
> Hello,
>
> I am new to node.js and try to do the following:
>
> read items from file (database entries)
>  for each item do expensive I/O operation (download stuff)
>  with the results do another expensive I/O operation (send mail)
>
> my approach in node.js involves map from async and looks like this:
>
> var async = require("async");
> database.read(arg, function (error, results) {
>  async.map(results, downloadFunction, function(err, results) {
>   async.map(results, sendFunction, function() {
>   });
>  });
> });
>
> This does not work as expected. Particularly async.map does not work
> as expected, e.g.
>
> function small(char, callback) {
>  callback("error occured", char.toLowerCase());
> };
>
> async.map(["a", "b"], small, function(err, result){
>    console.log(err);
>    console.log(result);
> });
>
> results in:
>
> error occured
> [ 'a' ]
>
> which I do not understand. As said, I am completly new to node.

Your "small" function always passes an error to the callback.
You should pass null instead of "error occurred", unless of course a
real error occurs.
If you make that change, your code will work fine.

One more thing ...
In the callback for database.read above, you should check whether
error has a value and not call async.map if it does. That's the case
for every callback function that can be passed an error.

-- 
R. Mark Volkmann
Object Computing, Inc.

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

Reply via email to