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:>
Can I promisify a stream?
No. While a stream continuously emits events, a promise resolves only once. They have completely different semantics (even if both use asynchronous callbacks).
You can make a promise for a stream that ends, see the EventEmitterPromisifier example in BlueBirds documentation - but that's not what your twitter stream example does.
Running this code does not log a tweet and no error is thrown.
Because T.stream()
is a synchronous factory function that returns a stream object. You don't need - you cannot - use streamAsync
, as it will never invoke the implicitly passed callback.