Created
December 8, 2014 08:00
-
-
Save phillipj/9aa46af4ef0adc03017a to your computer and use it in GitHub Desktop.
Stream -> promise -> stream
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 lifestyle = require('lifestyle'); | |
var through2 = require('through2'); | |
var client = new lifestyle.FinnClient('http://api.finn.no/iad/'); | |
var mapToAd = through2.obj(function (adId, encoding, callback) { | |
client.getAd(adId).then(function(ad) { | |
this.push(ad); | |
}.bind(this), function(err) { | |
console.error('YIKES, GOT ERROR!', err); | |
}).finally(callback); | |
}); | |
var pluckTitle = through2.obj(function (ad, encoding, callback) { | |
this.push(ad.title); | |
callback(); | |
}) | |
console.log('Enter any adId...'); | |
process.stdin | |
.pipe(mapToAd) | |
.pipe(pluckTitle) | |
.pipe(process.stdout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment