This package has been deprecated

Author message:

No longer maintained.

thenstream

1.0.0 • Public • Published

thenstream

Construct a Readable stream from a thenable. Useful if you don't have the actual stream yet.

Installation

npm install thenstream

Usage

With Legendary installed:

var Thenstream = require('thenstream');
var Promise = require('legendary').Promise;
 
var p = new Promise(function(resolve) {
  setTimeout(function() {
    resolve(getReadableStreamSomehow());
  }, 2000);
});
 
var readable = new Thenstream(p)
readable.on('readable', function() {
  var chunk;
  while (null !== (chunk = readable.read())) {
    console.log('got %d bytes of data', chunk.length);
  }
});

API

thenstream exports a single class, Thenstream.

new thenstream.Thenstream(thenable)

Subclass of stream.Readable. Can be called without new.

The returned stream is immediately readable, but no data will be available until thenable fulfils with a readable stream. The thenable is assimilated along the lines of the Promise Resolution Procedure. Any error in assimilation will be emitted (after the constructor has returned) as an error event. Similarly an error event will be emitted if the thenable does not fulfil with something that looks like a readable stream.

Note: thenables-for-thenables are not supported. If you need to handle such thenables you should wrap them using your promise library of choice, prior to creating the thenstream. Legendary would be a great choice.

Package Sidebar

Install

npm i thenstream

Weekly Downloads

0

Version

1.0.0

License

ISC

Last publish

Collaborators

  • novemberborn