Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const taskArgs = (this.config.args || []).slice()
let taskDomain = this.state.taskDomain
const exitMethod = unbounded.binder.call(this.itemCompletionCallback, this)
let method = this.config.method
// Check that we have a method to fire
if (!method) {
const error = new Error(
`The task [${this.names}] failed to run as no method was defined for it.`
)
this.emit('error', error)
return this
}
// Bind method
method = unbounded.binder.call(method, this)
// Handle domains
if (domain) {
// Prepare the task domain if we want to and if it doesn't already exist
if (!taskDomain && this.config.domain !== false) {
this.state.taskDomain = taskDomain = domain.create()
taskDomain.on('error', exitMethod)
}
} else if (this.config.domain === true) {
const error = new Error(
`The task [${this.names}] failed to run as it requested to use domains but domains are not available.`
)
this.emit('error', error)
return this
}
fire() {
// Prepare
const taskArgs = (this.config.args || []).slice()
let taskDomain = this.state.taskDomain
const exitMethod = unbounded.binder.call(this.itemCompletionCallback, this)
let method = this.config.method
// Check that we have a method to fire
if (!method) {
const error = new Error(
`The task [${this.names}] failed to run as no method was defined for it.`
)
this.emit('error', error)
return this
}
// Bind method
method = unbounded.binder.call(method, this)
// Handle domains
if (domain) {
addMethod(method, opts = {}) {
method = unbounded.binder.call(method, this) // run the taskgroup method on the group, rather than itself
method.isTaskGroupMethod = true
if (!opts.name) opts.name = 'taskgroup method for ' + this.name
if (!opts.args)
opts.args = [this.addTaskGroup.bind(this), this.addTask.bind(this)]
if (opts.storeResult == null) opts.storeResult = false // by default, hide result for methods
this.addTask(method, opts)
return this
}