-
-
Save bmpvieira/6f3eca6678f7f25e321e8b63b75e2c71 to your computer and use it in GitHub Desktop.
Trying to get streams to work
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 through = require('through2') | |
var pumpify = require('pumpify') | |
var request = require('request') | |
var getProjects = function (cb) { | |
var stream = pumpify.obj( | |
ex(), | |
sendRequest() // Returns a JSON object | |
) | |
return stream | |
// if (cb) { stream.pipe(concat(cb)) } else { return stream } | |
} | |
function ex (variable) { | |
var stream = through.obj(transform) | |
return stream | |
function transform (obj, enc, next) { | |
this.push(obj) | |
next() | |
} | |
} | |
// SendRequest | |
// - Internal function used to request a URL in a STREAM friendly manner | |
function sendRequest () { | |
var stream = through.obj(transform) | |
return stream | |
function transform (query, enc, next) { | |
console.log(query) | |
var self = this | |
self.push('hey' + '\n') | |
next() | |
} | |
} | |
var pipeline = getProjects() | |
pipeline.write('hello') | |
pipeline.pipe(process.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment