Construct a Readable stream from a thenable. Useful if you don't have the actual stream yet.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


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

Deprecation Notice

This module is no longer maintained. You can achieve a similar effect like this:

'use strict'

const PassThrough = require('stream').PassThrough

function streamify (thenable, opts) {
  const stream = new PassThrough(opts)

    .then(input => input.pipe(stream))
    .catch(err => stream.emit('error', err))

  return stream

This won't fully replace this module but it should suffice for most use cases.


npm install thenstream


With Legendary installed:

var Thenstream = require('thenstream');
var Promise = require('legendary').Promise;

var p = new Promise(function(resolve) {
  setTimeout(function() {
  }, 2000);

var readable = new Thenstream(p)
readable.on('readable', function() {
  var chunk;
  while (null !== (chunk = {
    console.log('got %d bytes of data', chunk.length);


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.