From 236c7aa223c1a93bd59746699470288cc3f500a4 Mon Sep 17 00:00:00 2001 From: Pepper Date: Wed, 7 May 2014 14:12:04 -0400 Subject: fixed --- using_Q/ls-test-3.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'using_Q/ls-test-3.js') diff --git a/using_Q/ls-test-3.js b/using_Q/ls-test-3.js index 93ca560..2a57895 100644 --- a/using_Q/ls-test-3.js +++ b/using_Q/ls-test-3.js @@ -3,27 +3,29 @@ Q = require('q'); var childProcess = require('child_process'), ls; function dumper(content){ console.log(JSON.stringify(content)); -} +} function go_big(){ - var promise_chain = Q.fcall(function(){}); + var promise_chain = Q.fcall(function(){ console.log("chain start") }); - var sync_operations = [ "ls | grep \"[^a-z]\"", "cat" ]; + var sync_operations = [ "ls | grep \"[^a-z]\"", "echo a" ]; sync_operations.forEach(function(async_op) { var promise_link = function() { var deferred = Q.defer(); - child_process.exec(async_op, function(error, stdout, stderr) { + childProcess.exec(async_op, function(error, stdout, stderr) { var result = { "error" : error, "stdout" : stdout, "stderr" : stderr }; deferred.resolve(result); }); + //sh.on("close", function(){ + //}); return deferred.promise; }; - // add the link onto the chain promise_chain = promise_chain.then(promise_link); }); return promise_chain } go_big().then(function(result){ dumper(result) } ) -//didn't quite get this one //https://coderwall.com/p/ijy61g +//oh right, it will return only last result, if you want all of them, need to pass something like results hash and +//push new results inside. -- cgit v1.2.3-70-g09d2