Last active
January 4, 2016 01:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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