I am new super new to Promises and Node and am curious about using promises with streams. Can I promisify a stream? Using Bluebirdjs and the Twit module I have the following:>
I ended up using RxJS implementing observables with streams.
var sanFrancisco = [ '-122.75', '36.8', '-121.75', '37.8' ]
var stream = T.stream('statuses/filter', { locations: sanFrancisco });
var source = Rx.Node.fromEvent(stream, 'tweet');
var observer = Rx.Observer.create(
function (tweet) {
// THIS IS WHERE EACH TWEET SHOULD COME FROM THE STREAM
console.log(tweet);
},
function (err) {
console.log('Error getting tweets: ' + err);
},
function () {
console.log('Completed');
}
);
source.subscribe(observer);
I ended up having to use RX.Observable.fromEvent instead of Rx.Node.fromStream because, the Twit module must handle the actual stream behind the scenes but exposing it through and EventEmitter, they probably shouldn't have named it T.stream.