Last active
April 7, 2017 15:09
-
-
Save IsmailM/dbb61b60797b0ccc006163ddb2f765a5 to your computer and use it in GitHub Desktop.
Trying to get streams to work
This file contains hidden or 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('hello'), | |
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) { | |
var query = variable | |
this.push(query) | |
} | |
} | |
// 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') | |
} | |
} | |
getProjects().pipe(process.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment