不要怂,就是干,撸起袖子干!

Commit 091a4a24 by sdepold

added possibility to skip queries once a query failed

1 parent 5d6ec6ef
Showing with 30 additions and 15 deletions
......@@ -37,29 +37,44 @@ module.exports = (function() {
return this.eventEmitter.run()
}
QueryChainer.prototype.runSerial = function() {
var self = this
QueryChainer.prototype.runSerial = function(options) {
var self = this
options = Utils._.extend({
skipOnError: false
}, options)
var exec = function() {
var serial = self.serials.pop()
if(serial) {
var emitter = serial.klass[serial.method].apply(serial.klass, serial.params)
emitter.success(function() {
if(serial.options && serial.options.success) {
serial.options.success(serial.klass, function() {
self.finishedEmits++
exec()
})
} else {
self.finishedEmits++
exec()
}
}).error(function(err) {
serial.options = serial.options || {}
serial.options.before && serial.options.before(serial.klass)
var onSuccess = function() {
serial.options.after && serial.options.after(serial.klass)
self.finishedEmits++
exec()
}
var onError = function(err) {
serial.options.after && serial.options.after(serial.klass)
self.finishedEmits++
self.fails.push(err)
exec()
})
}
if(options.skipOnError && (self.fails.length > 0)) {
onError('Skipped due to earlier error!')
} else {
var emitter = serial.klass[serial.method].apply(serial.klass, serial.params)
emitter.success(function() {
if(serial.options.success)
serial.options.success(serial.klass, onSuccess)
else
onSuccess()
}).error(onError)
}
} else {
self.wasRunning = true
finish.call(self)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!