Skip to content

Instantly share code, notes, and snippets.

@joaojeronimo
Last active January 4, 2016 01:59
Show Gist options
  • Save joaojeronimo/8552014 to your computer and use it in GitHub Desktop.
Save joaojeronimo/8552014 to your computer and use it in GitHub Desktop.
A very simple example on how to use CrowdProcess in Node.js: https://github.com/CrowdProcess/node-crowdprocess
var credentials = require('./credentials.json');
var CrowdProcess = require('crowdprocess')(credentials);
function Run (d) {
return d*2;
}
var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
CrowdProcess(data, Run, function (results) {
console.log('results:', results);
});
var credentials = require('./credentials.json');
var CrowdProcess = require('crowdprocess')(credentials);
var Readable = require('stream').Readable;
var Writable = require('stream').Writable;
// the program
function Run(d) {
return d;
}
// input stream for the program
var data = new Readable({objectMode: true});
var n = 110;
data._read = function _read () {
if (--n)
data.push(n);
else
data.push(null);
};
// results stream
var results = new Writable({objectMode: true});
results.write = function write (chunk, encoding, cb) {
console.log('got result:', chunk);
if (cb)
cb();
return true;
};
// awesome oneliner
data.pipe(CrowdProcess(Run)).pipe(results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment