Created
January 4, 2016 09:50
-
-
Save kabbi/862f081b8e054783909b to your computer and use it in GitHub Desktop.
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
'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