I'm trying to run something before and after a task is completed in JakeJS and I'm not sure how to do it.
Currently, I need to attach the function to each task like this and it's tedious.
var complete = function() {
// Do something when a task is completed
}
task("someTask", function() {
// Do something
})
.addListener("complete", complete)
task("anotherTask", function() {
// Do something
})
.addListener("complete", complete)
I can probably wrap task by yet another function but that's just a ugly hack so I wonder if I can do something like this.
jake.addListener("afterTaskCompleted", function() {
// Do something when a task is completed
})
Jake has a start event so what I did is iterated over the collection and checked whether it's a task; if it is then I've attached the handler to the completed event.
jake.addListener("start", function (e) {
_.forOwn(jake.Task, function(task, name) {
if (task.name && task.prereqs && name !== "__root__") {
task.addListener("complete", function() { console.log() })
}
})
})
p.s. I'm using lodash to iterate over the collection.