2.0.1 • Published 5 years ago

bluebird-to-readable v2.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Why Bluebird and not Core Promise?

This project is explicitly designed to work with Bluebird Promises because of the feature-rich API it provides. Not convinced?

Install

  npm i -S bluebird-to-readable

Usage

import Bluebird from 'bluebird';
import {BluebirdToReadable} from 'bluebird-to-readable';

const promise: Bluebird<string> = Bluebird.resolve(`They're just questions Leon.\r\n`);

// The Type Generic is optional and defaults to `any`
const readable = BluebirdToReadable<string>(promise);

readable.pipe(process.stdout); // "They're just questions Leon."

API

BluebirdToReadable<T=any>(Bluebird<T>)

This returns a paused (or non-flowing) Readable stream. Calling .pipe() or using the readable event and invoking .read() will un-pause or begin flowing data from the readable stream into the Transform or Writable stream.

If the Bluebird promise is destroyed before the promise has been resolved, and Bluebird has been configured to allow cancellation i.e., Bluebird.config({cancellation: true}); the promise will be cancelled.

If for any reason the resolved value fails to push onto the readable stream i.e., this.push(resolvedValue) returns false, the promise will emit an error, and destroy itself.

To run example.ts install locally and run npm run example.