Promises and streams using Bluebird.js and Twitter stream

后端 未结 3 2110
走了就别回头了
走了就别回头了 2021-02-09 11:59

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:

3条回答
  •  我在风中等你
    2021-02-09 12:21

    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.

提交回复
热议问题