Skip to content

Instantly share code, notes, and snippets.

@eguneys
Created November 9, 2014 15:52
Show Gist options
  • Save eguneys/cc11fb73f7f02266e014 to your computer and use it in GitHub Desktop.
Save eguneys/cc11fb73f7f02266e014 to your computer and use it in GitHub Desktop.
Highland stream consume push within promise fail
var util = require('util'),
cheers = require('cheers'),
_ = require('highland'),
Q = require('q');
function JunkStrat() {}
JunkStrat.prototype.authorStream = function() {
return _(['a', 'b', 'c', 'd']);
};
JunkStrat.prototype.linkStream = function() {
var self = this;
return this.authorStream()
.consume(function(err, res, push, next) {
self.getPromise().then(function() {
push(null, res);
next(self.linkPageStream(1));
});
});
};
JunkStrat.prototype.linkPageStream = function(x) {
var self = this;
return _(function(push, next) {
push(null, x);
next(self.linkPageStream(x + 1));
});
};
JunkStrat.prototype.getPromise = function() {
var q = Q.defer();
setTimeout(function() {
q.resolve();
}, 1000);
return q.promise;
};
module.exports = JunkStrat;
@eguneys
Copy link
Author

eguneys commented Nov 9, 2014

Here's a test for this which fails:

    describe 'junk', ->
        beforeEach ->
            @junkS = new require('junk')()

        it 'article link stream should be populated', (done) ->
            links = @junkS.linkStream()
            links.take(3).toArray((result) ->
                console.log(result)
                done
            )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment