Skip to content
JoshRagem edited this page Jun 22, 2013 · 1 revision

With Step.js

var QuickConnect = require('qcnode').QuickConnect,
step = require('step'),
fs = require('fs'),
qc = new QuickConnect

qc.isolate('step')
.command('example')
.dcf(function(data,qc){
    step(
      // Loads two files in parallel
      function loadStuff() {
        fs.readFile(__filename, this.parallel());
        fs.readFile("/etc/passwd", this.parallel());
      },
      // Show the result when done
      function showStuff(err, code, users) {
        if (err) throw err;
        console.log(code);
        console.log(users);
        qc.asyncStackContinue()
      }
    )
    return qc.WAIT_FOR_DATA
})

qc.run(['step','example'],{},{})

Notes

This one was kind of a stretch. QC does everything that step does (and more), except for counting multiple async calls and providing the one, unified callback for those multiple calls.

Let's see how this works; you make several calls and your callback gets an error and any actual results you have. What if you have multilpe errors? what if you actually wanted to stop if there was an error? what if you want to ignore errors? what if there are no results and you just need to know if it succeeded?

We haven't figured out answeres to these questions that will work everywhere, so we have not put it in QC. We may put in some code so you can add 'mixins' to the qc environment--that would allow you to use whatever you needed to use for your use cases.

Clone this wiki locally