lib/promise.js
function promisfyStream(stream) {
    var ret = new Promise(), called;

    function errorHandler() {
        if (!called) {
            called = true;
            spreadArgs(ret.errback, arguments, ret);
            stream.removeListener("error", endHandler);
            stream.removeListener("end", endHandler);
            stream = ret = null;
        }
    }

    function endHandler() {
        if (!called) {
            called = true;
            spreadArgs(ret.callback, arguments, ret);
            stream.removeListener("error", endHandler);
            stream.removeListener("end", endHandler);
            stream = ret = null;
        }
    }

    stream.on("error", errorHandler).on("end", endHandler);
    return ret.promise();
}
function promisfyStream(stream) {
    var ret = new Promise(), called;

    function errorHandler() {
        if (!called) {
            called = true;
            spreadArgs(ret.errback, arguments, ret);
            stream.removeListener("error", endHandler);
            stream.removeListener("end", endHandler);
            stream = ret = null;
        }
    }

    function endHandler() {
        if (!called) {
            called = true;
            spreadArgs(ret.callback, arguments, ret);
            stream.removeListener("error", endHandler);
            stream.removeListener("end", endHandler);
            stream = ret = null;
        }
    }

    stream.on("error", errorHandler).on("end", endHandler);
    return ret.promise();
}
function promisfyStream ( stream ) { var ret = new Promise ( ) , called ; function errorHandler ( ) { if ( ! called ) { called = true ; spreadArgs ( ret . errback , arguments , ret ) ; stream . removeListener ( "error" , endHandler ) ; stream . removeListener ( "end" , endHandler ) ; stream = ret = null ; } } function endHandler ( ) { if ( ! called ) { called = true ; spreadArgs ( ret . callback , arguments , ret ) ; stream . removeListener ( "error" , endHandler ) ; stream . removeListener ( "end" , endHandler ) ; stream = ret = null ; } } stream . on ( "error" , errorHandler ) . on ( "end" , endHandler ) ; return ret . promise ( ) ; }
Wraps a stream in a promise waiting for either the `"end"` or `"error"` event to be triggered.

```
comb.promisfyStream(fs.createdReadStream("my.file")).chain(function(){
console.log("done reading!");
});

```

@param stream stream to wrap
@return {comb.Promise} a Promise is resolved if `"end"` is triggered before `"error"` or rejected if `"error"` is triggered.
@memberOf comb
@static
Wraps a stream in a promise waiting for either the end or error event to be triggered .