Step.js return callback in middle step
I am so confused with StepJS. What I am trying to do is in STEP 3 if
data.message is defined then I should update my update_stat object with
"err = yes" and return original "cb" without going in other steps.
if you look at Step-3, when I comment line below:
# update_stat.err = "yes"
STEP - 4/5/6/7 are not executed and callback 'cb' goes back but when I
uncomment above line and set "err" value to "yes"
Steps 4,5,6,7 are executed : ( any help will be appreciated
update: (doc, cb) ->
self = this
update_stat = {
err: "no",
type: "none",
message: "none"
}
Step(
() ->
console.log("step - 1")
step_callback = this
self.parse_interface(step_callback)
return
, (err, data) ->
# console.log("=========== parse interface data")
# console.info(data)
console.log("step - 2")
step_callback = this
if _.isArray(data) and data.length is 0
step_callback(undefined, true)
else
self.update_interface(data, step_callback)
return
, (err, data) ->
console.log("step - 3")
step_callback = this
# throw err if err
console.log("=========== RESULT OF UPDATE interface")
console.info(data)
if data.message?
# update_stat.err = "yes"
# update_status.type = "update interface"
# update_status.message = data.message
cb(undefined, update_stat)
else
self.parse_routes(step_callback)
return
, (err, data) ->
console.log("step - 4")
step_callback = this
if _.isArray(data) and data.length is 0
step_callback(undefined, true)
else
self.update_routes(data, step_callback)
return
, (err, data) ->
step_callback = this
console.log("step - 5")
console.log("=========== RESULT OF UPDATE Routes")
console.info(data)
throw err if err
if data.message?
# console.log("I am here..............")
# update_status.error = true
# update_status.type = "update routes"
# update_status.message = data.message
# console.info(update_stat)
cb(undefined, update_stat)
return
self.parse_vlan(step_callback)
return
, (err, data) ->
console.log("step - 6")
console.log(data)
step_callback = this
if _.isArray(data) and data.length is 0
step_callback(undefined, true)
else
self.update_vlans(data, step_callback)
return
, (err, data) ->
console.log("step - 7")
console.log("=========== RESULT OF UPDATE vlans")
console.info(data)
throw err if err
if data.message?
# update_status.error = true
# update_status.type = "update vlans"
# update_status.message = data.message
cb(undefined, update_stat)
else
cb(undefined, update_stat)
)
No comments:
Post a Comment