-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support drop(), issue #11 #75
Conversation
return this.consume(function (err, x, push, next) { | ||
if (err) { | ||
push(err); | ||
if (n < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be n >= 0
?
Thanks for this, looks good apart from the comment I added. You might want to add a test for error handling to make sure it does what's expected here. |
@caolan thanks! I'm wondering how to trigger err during consuming.. are there some tests that do anything similar? Will extend test cases and re-apply. |
@alexanderbeletsky you'll have to use a generator stream and |
@caolan will be happy if you take a look on updated version :) |
* @id drop | ||
* @section Streams | ||
* @name Stream.drop(n) | ||
* @param {Number} n - n - integer representing number of values to read from source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate n -
.
I'm a little concerned about the handling of errors.
|
@vqvu I think your concerns are right.. I just wasn't sure about right behavior. Would be happy to clarify. The current behavior, exports['drop - errors'] = function (test) {
test.expect(3);
var s = _(function (push, next) {
push(null, 1),
push(new Error('error'), 2),
push(null, 3),
push(null, 4),
push(null, _.nil)
});
var f = s.drop(2);
f.pull(function (err, x) {
test.equal(err.message, 'error');
});
f.pull(function (err, x) {
test.equal(x, 4);
});
f.pull(function (err, x) {
test.equal(x, _.nil);
});
test.done();
}; Expected behaviour, exports['drop - errors'] = function (test) {
test.expect(3);
var s = _(function (push, next) {
push(null, 1),
push(new Error('error'), 2),
push(null, 3),
push(null, 4),
push(null, _.nil)
});
var f = s.drop(2);
f.pull(function (err, x) {
test.equal(x, 4);
});
f.pull(function (err, x) {
test.equal(x, _.nil);
});
test.done();
};
exports['drop - errors 2'] = function (test) {
test.expect(3);
var s = _(function (push, next) {
push(null, 1),
push(null, 2),
push(new Error('error'), 3),
push(null, 4),
push(null, _.nil)
});
var f = s.drop(2);
f.pull(function (err, x) {
test.equal(err.message, 'error');
});
f.pull(function (err, x) {
test.equal(x, _.nil);
});
test.done();
}; ? |
I'm not sure. The reason |
@caolan Good point. It's probably better to be safe. I'm more used to the Rx way of handling errors, so I think I was thrown off by the "more than one error per stream" semantics that we have here. @alexanderbeletsky I'm now OK with keeping the
An error shouldn't cause the stream to stop, since no other stream operators do this. |
"An error shouldn't cause the stream to stop" - correct :) - since it's lazy it's up to the consumer to decide whether to continue reading. Obviously, if the stream is a data source and the error is unrecoverable, then the next value will just be |
@vqvu @alexanderbeletsky where are we with this? |
@caolan I need to correct that to latest discussed behaviour. Will try to re-submit asap. |
@alexanderbeletsky what's the status on this? Current branch has merge conflicts so you might want to rebase on master. |
@quarterto unfortunately, I have to admit I failed to understand how the error handling should work, so my progress just stopped. I will try to rebase and re-submit so we can discuss it again. |
@alexbeletsky sorry for the delay on this. regarding the question on how error handling should work : all errors should be passed along downstream. that would mean replace + if (err) {
+ push(err);
+ if (n < 0) {
+ next();
+ }
+ else {
+ push(null, nil);
+ }
+ } by + if (err) {
+ push(err);
+ next();
+ } do you still have the motivation / available time to finish this PR or would you prefer if someone can take it over ? |
Yes, I'm still willing to help and make this PR happen! On Mon, Jan 5, 2015, 21:21 jeromew notifications@github.com wrote:
|
What's the status of this? Do we even need it now that we have transducers? |
We don't need it, but I think we should have it as a pair with |
Yep, it makes sense to have the both of them. @alexbeletsky There's not very much left on this to do so I grabbed the changes from your pull request using the hub tool and I can make the minor adjustments for you. Do you mind if I finish this pull request on your behalf? It's just it's been open for a while and it would be nice to close it. |
@svozza please, go ahead! Thanks a lot for your help, if any question plz ping me. |
No probs! |
Superseded by #244. |
Provides support for
.drop()