Created
November 9, 2014 15:52
-
-
Save eguneys/cc11fb73f7f02266e014 to your computer and use it in GitHub Desktop.
Highland stream consume push within promise fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a test for this which fails: