Skip to content

Instantly share code, notes, and snippets.

@jfhbrook
Created August 11, 2010 00:46
Show Gist options
  • Save jfhbrook/518295 to your computer and use it in GitHub Desktop.
Save jfhbrook/518295 to your computer and use it in GitHub Desktop.
I've been thinking about dataflow-paradigm languages. Events would make for a handy way to deal with edges.
EE = require('events').EventEmitter
//edges isn't well-thought-out. I want to be able to hold it as a string but treat it as a pointer. :/
// I could also make edges contain both a name *and* an EE-/type/ object, for more flex. Might be The Way.
function BlackBox(fxn, edges) {
blackbox = new EE;
blackbox.input = [none, none];
blackbox.edges = edges;
blackbox.on('input' function(index,val) {
if ( index < input.length() ) {
inputVals[index] = val;
} else {
console.log("WARNING: Something somewhere thinks there are more inputs than there should be.");
}
//Checks to make sure all values in input are defined
if ((input[0] !== undefined && (input[1] !== undefined)) {
outs = fxn.apply(this,input);
if ( index < edges.length() ) {
edges.forEach( function(edge, index) {
edge.emit('input', outs[index]);
});
} else {
console.log("WARNING: Something somewhere thinks there are more outputs than there should be.");
}
}
});
//For graphviz
blackbox.dot = g(edges);
return blackbox;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment