Callback hell is a place you decide to go on your own. I'm not following you
down there...
Here is an alternative example made in callback heaven, where we embrace
asyncronous control flow like our first-born:
var async = require('async-array').async
var fs = require('fs')
var spawn = require('child_process').spawn
fs.readdir('/my/amazing/directory/', function (err, filenames) {
if (err) throw err
async(filenames)
// Only keep files
.filter(function (filename, i, next) {
fs.lstat(filename, function (err, stat) {
if (err) return next(err)
next(null, stat.isFile())
})
})
// Pipe files to my-awesome-process
.forEach(function (filename, i, next) {
var awesome = spawn('my-awesome-process')
fs.createReadStream(filename).pipe(awesome.stdin)
awesome.on('exit', next)
})
// Run it
.exec(function (err) {
if (err) throw err
console.log('All done')
})
})
I encourage you to try make your own control flow library. It helps you to get
your head around callbacks and all that jazz.
Tim
On Thu, Mar 14, 2013 at 01:32:18PM -0700, Sebi wrote:
> Many functions in NodeJS have a Sync pendant to the non-blocking functions.
> Why is there no blocking pendant in the child_process module?
>
> I've giving up as I tried to iterate over a directory and call for every
> file
> child.exec....
>
> how should my app now, that every process completed his task?
> I'm going to run in trouble, because to use a timer to check that seems to
> be not a powerful resolution.
>
> Think there should be a sync pendant in the core child module....
>
> Sometimes you're going to the "callback" hell...
>
> --
> --
> 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.
>
>
--
--
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.