diff options
| author | pepper <pepper@chimecrisis.com> | 2014-05-06 13:46:24 -0700 |
|---|---|---|
| committer | pepper <pepper@chimecrisis.com> | 2014-05-06 13:46:24 -0700 |
| commit | c552945defe89e3055f2305fe598c5db0f0b8355 (patch) | |
| tree | 277fcb07642c40d8a04587f110f0466be74a5e32 /using_Q/ls-test-3.js | |
| parent | 37aa15421f6bbd3a6ce605ee8f9a13bb3bc84c2b (diff) | |
updated
Diffstat (limited to 'using_Q/ls-test-3.js')
| -rw-r--r-- | using_Q/ls-test-3.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/using_Q/ls-test-3.js b/using_Q/ls-test-3.js new file mode 100644 index 0000000..93ca560 --- /dev/null +++ b/using_Q/ls-test-3.js @@ -0,0 +1,29 @@ +#!/usr/local/bin/node +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 sync_operations = [ "ls | grep \"[^a-z]\"", "cat" ]; + sync_operations.forEach(function(async_op) { + var promise_link = function() { + var deferred = Q.defer(); + child_process.exec(async_op, function(error, stdout, stderr) { + var result = { "error" : error, "stdout" : stdout, "stderr" : stderr }; + deferred.resolve(result); + }); + 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 |
