-
Notifications
You must be signed in to change notification settings - Fork 6
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
Returning Errors From sequence() #2
Comments
sequence()
If a promise request within the function source(index, data, delay) {
if (/*condition*/) {
return this.query('insert into users(...) values(...)')
.catch(function (error) {
return promise.resolve({
success: false,
result: error
});
});
}
} This will override any failure. You can also add override for the resolve, if you want to uniform the result for easier processing after the resolution, like this: function source(index, data, delay) {
if (/*condition*/) {
return this.query('insert into users(...) values(...)')
.then(function (data) {
return {
success: true,
result: data
};
})
.catch(function (error) {
return promise.resolve({
success: false,
result: error
});
});
}
} With this you will have your sequence carry on regardless of the insert result, while within your processing function you can easily see which request was successful and which failed. |
Actually, now that I consider your thoughts and look again, I see that the problem lies one layer above:
The |
The You can bring it up one level, if you want, make your code ignore the result from the sequence: api.parsers.processCsvStream = function (passedStream, processor) {
return spex.stream.read(passedStream.pipe(csv.parse()), function (index, data, delay) {
return spex.sequence(function (index) {
if (index < data.length) {
return processor(data[index]);
}
})
.catch(function () {
return promise.resolve();
});
});
} And by the way, I'm not sure if your api.parsers.processCsvStream = function (passedStream, processor) {
return spex.stream.read(passedStream.pipe(csv.parse()), function (index, data, delay) {
if (data.length) {
return data[0];
}
});
} |
Actually, I would like to end up with a success "report", and the PS: The function |
Method If you want method |
But, |
I ended up tracking it myself, per your suggestion, although I still think it (returning errors) would be a great addition to any function that has a
and
|
Method
|
The
sequence()
function has atrack
parameter that allows the function to return resolved data. I would like to propose that one adds functionality to track/capture rejected data too.My particular scenario would be in file streaming. I use
sequence()
to process the data in large files into a database. Some rows fail from being inserted due to a variety of reasons. When an error is thrown/rejected, the whole run ends. In some cases, I would rather have an option that the sequence continues (add askip
boolean param) and/or that the problem rows be collected and reported (add atrackErrors
param).Looking at the code, my first idea would be to implement via checking in each
catch()
insequence()
for those params. Theskip == true
would result in no rejections and thetrackErrors == true
would, much liketrack
, push data into the results.Any suggestions or alternatives? I'd be willing to put in a pull request if so desired.
The text was updated successfully, but these errors were encountered: