bluebird-to-readable

2.0.1 • Public • Published

bluebird-to-readable

TypeScript library to convert a Bluebird Promise to a Readable stream.

npm version Travis Status Coverage Status Typescript 3.2 MIT License Node 10.x.x

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.

Package Sidebar

Install

npm i bluebird-to-readable

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

10.8 kB

Total Files

5

Last publish

Collaborators

  • jnobo