First day at programming in Node today. I've been getting along nicely all day but have some across something weird. I'm probably not understanding Node's asynchronism or something.
I have a function that executes a shell command:
function puts( error, stdout, stderr ) { sys.puts( stdout ); }
Then I execute some commands:
exec( "foo", puts );
myarr.keys( "mykey", function ( err, replies ) {
replies.forEach( function ( reply, i ) {
exec( "bar" );
});
});
exec( "fuzz", puts );
exec( "buzz", puts );
so the two last things that are meant to be executed are fuzz and then buzz. However, it seems that fuzz and buzz happen at some random point in the loop and bar is the thing that gets printed last (sometimes). myarr is an array that I build by connecting to a Redis database.
Do I have to force Node to do the loop synchronously or something? I am using Redis clients in the code.. could these cause problems? Any ideas? Many thanks :).