Skip to content

Instantly share code, notes, and snippets.

@kabbi
Created January 4, 2016 09:50
Show Gist options
  • Save kabbi/862f081b8e054783909b to your computer and use it in GitHub Desktop.
Save kabbi/862f081b8e054783909b to your computer and use it in GitHub Desktop.
'use strict';
const from = require('from2');
class StdoutNode {
constructor(id) {
this.id = id;
}
getInputs() {
return [{
id: 'stdout',
stream: process.stdout
}];
}
getOutputs() {
return [];
}
}
class StringNode {
constructor(id, props) {
this.id = id;
this.props = props;
this.str = props.str;
this.ptr = 0;
this.stream = from((size, next) => {
setTimeout(() => {
next(null, this.str[this.ptr]);
if (++this.ptr === this.str.length) {
this.ptr = 0;
}
}, 300);
});
}
getInputs() {
return [];
}
getOutputs() {
return [{
id: 'output',
stream: this.stream
}];
}
}
const node1 = new StringNode('str', {
str: 'hello,world!'
});
const node2 = new StdoutNode('std');
node1.getOutputs()[0].stream.pipe(node2.getInputs()[0].stream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment