## Classes
SuperTask
Task

Created through addLocal, addForeign and get methods.

## SuperTask **Kind**: global class * [SuperTask](#SuperTask) * [new SuperTask()](#new_SuperTask_new) * _instance_ * [.addLocal(name, taskFunction)](#SuperTask+addLocal) ⇒ * [.addForeign(name, taskFunction)](#SuperTask+addForeign) ⇒ * [.addRemote(name, taskFunction, handler)](#SuperTask+addRemote) ⇒ * [.do(taskName, ...arguments, callback)](#SuperTask+do) * [.apply(taskName, context, arguments, callback)](#SuperTask+apply) * [.remove(name)](#SuperTask+remove) ⇒ Boolean * [.has(name)](#SuperTask+has) ⇒ Boolean * [.get(name)](#SuperTask+get) ⇒ Object * _static_ * [.ST_NONE](#SuperTask.ST_NONE) * [.ST_RESTRICTED](#SuperTask.ST_RESTRICTED) * [.ST_MINIMAL](#SuperTask.ST_MINIMAL) * [.ST_UNRESTRICTED](#SuperTask.ST_UNRESTRICTED) - ### new SuperTask() Creates new instance. **Returns**: Instance - Returns a new instance of the module. **Example** ```js var SuperTask = require('supertask'); var TaskManager = new SuperTask(); ``` - ### superTask.addLocal(name, taskFunction) ⇒ Creates a new local Task. A local task is a task that is not shared by any outside entity and usually performs slightly faster than shared or foreign tasks as there is no compilation or try/catch involved. **Kind**: instance method of [SuperTask](#SuperTask) **Returns**: [Task](#Task) | Param | Type | Description | | --- | --- | --- | | name | String | A unique name for this Task. | | taskFunction | function | The JS function of the Task. | - ### superTask.addForeign(name, taskFunction) ⇒ Creates a new foreign Task. A local task is a task that is not shared by any outside entity and usually performs slightly faster than shared or foreign tasks as there is no compilation or try/catch involved. **Kind**: instance method of [SuperTask](#SuperTask) **Returns**: [Task](#Task) | Param | Type | Description | | --- | --- | --- | | name | String | A unique name for this Task. | | taskFunction | function | The JS function or source with module.exports to be used as the function. Note that sources are compiled to a function before use with about a 30ms overhead on the first call unless precompile method of task is called beforehand. | - ### superTask.addRemote(name, taskFunction, handler) ⇒ Creates a new remote Task. Remote tasks do not exist in the local machine and instead a handler function is called to run the function with the arguments wherever the task is located. Note that the handler function takes arguments of [task, name, context, args, callback]. **Kind**: instance method of [SuperTask](#SuperTask) **Returns**: [Task](#Task) | Param | Type | Description | | --- | --- | --- | | name | String | A unique name for this Task. | | taskFunction | function | String | The JS function or source with module.exports to be used as the function. | | handler | function | A handler function that is called when the task is executed. | - ### superTask.do(taskName, ...arguments, callback) Run a task with the given arguments **Kind**: instance method of [SuperTask](#SuperTask) | Param | Type | Description | | --- | --- | --- | | taskName | String | Unique name of the task | | ...arguments | \* | Arguments that are passed to the Task. You can call this function with any number of arguments so long as the last argument is the callback. | | callback | function | The callback that handles the response. Note that the callback parameters are based on what the function calls the callback with but will include `error` as the first parameter as per usual NodeJS async calls. | - ### superTask.apply(taskName, context, arguments, callback) Run a task with the given arguments and context (this) **Kind**: instance method of [SuperTask](#SuperTask) | Param | Type | Description | | --- | --- | --- | | taskName | String | Unique name of the task | | context | Object | Passes as (this.property). Note that `call`, `apply`, `self`, `recurse` are reserved properties. | | arguments | Array | An array of arguments that are passed to the Task. | | callback | function | The callback that handles the response. Note that the callback parameters are based on what the function calls the callback with but will include `error` as the first parameter as per usual NodeJS async calls. | - ### superTask.remove(name) ⇒ Boolean Remove a task. **Kind**: instance method of [SuperTask](#SuperTask) **Returns**: Boolean - - Returns true if task existed and was removed or false if task did not exist | Param | Type | Description | | --- | --- | --- | | name | String | Name of the task. | - ### superTask.has(name) ⇒ Boolean Check if task exists. **Kind**: instance method of [SuperTask](#SuperTask) **Returns**: Boolean - exists | Param | Type | Description | | --- | --- | --- | | name | String | Name of the task. | - ### superTask.get(name) ⇒ Object Get a wrapped version of the task. **Kind**: instance method of [SuperTask](#SuperTask) **Returns**: Object - task | Param | Type | Description | | --- | --- | --- | | name | String | Name of the task. | - ### SuperTask.ST_NONE No permissions. Code runs JS only. **Kind**: static property of [SuperTask](#SuperTask) - ### SuperTask.ST_RESTRICTED Some permissions. Allows streams, Buffer, setTimeout, setInterval only **Kind**: static property of [SuperTask](#SuperTask) - ### SuperTask.ST_MINIMAL Minimal permissions. Allows all restricted permissions and __dirname, __filename, console globals. Includes a limited require('*') function with access to 'http', 'https', 'util', 'os', 'path', 'events', 'stream', 'string_decoder', 'url', 'zlib' **Kind**: static property of [SuperTask](#SuperTask) - ### SuperTask.ST_UNRESTRICTED UNSAFE, All permissions. Copies global scope. **Kind**: static property of [SuperTask](#SuperTask) - ## Task Created through [addLocal](#SuperTask+addLocal), [addForeign](#SuperTask+addForeign) and [get](#SuperTask+get) methods. **Kind**: global class * [Task](#Task) * [.do](#Task+do) * [.permission([permission])](#Task+permission) ⇒ SuperTaskPermissionFlag * [.globals([globals])](#Task+globals) ⇒ Object * [.sandbox([sandboxed])](#Task+sandbox) ⇒ Boolean * [.call([...arguments], callback)](#Task+call) * [.apply(context, arguments, callback)](#Task+apply) * [.precompile(context)](#Task+precompile) - ### task.do An alias for [call](#Task+call) function. **Kind**: instance property of [Task](#Task) | Param | Type | | --- | --- | | [...arguments] | arguments | | callback | function | - ### task.permission([permission]) ⇒ SuperTaskPermissionFlag Gets/Sets permission of the Task based on the given SuperTaskPermissionFlag such as [SuperTask#ST_NONE](SuperTask#ST_NONE) or [SuperTask#ST_MINIMAL](SuperTask#ST_MINIMAL). **Kind**: instance method of [Task](#Task) **Returns**: SuperTaskPermissionFlag - access | Param | Type | Description | | --- | --- | --- | | [permission] | SuperTaskPermissionFlag | Permission of the Task. | **Example** ```js var SuperTask = require('supertask'); var TaskManager = new SuperTask(); TaskManager.addLocal('minimaltask', function(callback) { setTimeout(callback, 1000); }, function(error, task) { task.permission(SuperTask.ST_MINIMAL); }); ``` - ### task.globals([globals]) ⇒ Object Gets/Sets global variables available to a the Task. **Kind**: instance method of [Task](#Task) **Returns**: Object - globals | Param | Type | Description | | --- | --- | --- | | [globals] | Object | Globals of the Task. | **Example** ```js var SuperTask = require('supertask'); var TaskManager = new SuperTask(); TaskManager.addLocal('ctask', function(callback) { callback(null, this.test); }, function(error, task) { task.globals({ test: 'yes' }); TaskManager.do('ctask', function(error, r1){ console.log(r1); // Output: yes }) }); ``` - ### task.sandbox([sandboxed]) ⇒ Boolean Gets/Sets Task's isSanboxed property. If a task is sandboxed it is determined to be likely for it to throw therefore it is wrapped around a try/catch block. By default all no local tasks are sandboxed. Error that is caught is passed to callback as the first argument. **Kind**: instance method of [Task](#Task) **Returns**: Boolean - sandboxed | Param | Type | Description | | --- | --- | --- | | [sandboxed] | Boolean | Sandbox property of the Task. | - ### task.call([...arguments], callback) An internal replacement for [do](#SuperTask+do) function. **Kind**: instance method of [Task](#Task) | Param | Type | | --- | --- | | [...arguments] | arguments | | callback | function | - ### task.apply(context, arguments, callback) An extension to [do](#SuperTask+do) function. Enables passing of call context (this) as the first argument followed by the call arguments as an array **Kind**: instance method of [Task](#Task) | Param | Type | Description | | --- | --- | --- | | context | Object | Context of the Task (this). | | arguments | Array | An array of arguments. | | callback | function | | - ### task.precompile(context) Allows for precompilation of the Task to save execution time on the first call. Note that to change the context you'll need to precompile the task again. Context is preserved. **Kind**: instance method of [Task](#Task) | Param | Type | | --- | --- | | context | Object | -