### tasksf

`1.3.18`
Need help reading this?

### Collection

Collection. Abstract class.

Basic collection class. Do NOT instantiate directly.

new Collection(complete: Function, recover: Function)
Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Instance Members
▸ constructor(complete, recover)

Task constructor

constructor(complete: Function, recover: Function)
Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
▸ attach(key, value)

Attaches variable with a key

Used to avoid using global variables or trying to scope in some way. After attach() you can get(). Attach will also keep the variable from GC.

attach(key: string, value: any)
Parameters
key `(string)` accessor for the variable
value `(any)` variable value
▸ detach(key)

Detaches variable with a key

detach(key: string)
Parameters
key `(string)` accessor for the variable
▸ get(key)

Gets variable with a key

get(key: string): any
Parameters
key `(string)` accessor for the variable
Returns
`any`: value variable value
▸ push(task)

Pushes task to the collection

push(task: Task): Collection
Parameters
task `(Task)` task to push
Returns
`Collection`: collection current collection
▸ unshift(task)

Unshifts task to the collection

unshift(task: Task): Collection
Parameters
task `(Task)` task to push
Returns
`Collection`: collection current collection
▸ remove(task)

Removes task from the collection

remove(task: Task): Collection
Parameters
task `(Task)` task to push
Returns
`Collection`: collection current collection
▸ run()

Runs all tasks in the collection

run()
▸ stop()

Stops all tasks in the collection

stop(): boolean
Returns
`boolean`: stopped stopped status
▸ reset()

Resets a stopped collection

reset(): boolean
Returns
`boolean`: reset reset status
▸ _complete()

Complete

Runs complete task

_complete()
▸ _recover(error)

Recover

Runs recover task

_recover(error: any)
Parameters
error `(any)`
▸ _chainTask(task)

Chain task

Attach the chain to the task

_chainTask(task: Task)
Parameters
task `(Task)` task to chain
▸ _unchainTask(task)

Unchain task

Detach the chain from the task

_unchainTask(task: Task)
Parameters
task `(Task)` task to chain
▸ _postTaskAdds()

Probe post add actions

Try all post add triggers

_postTaskAdds()
▸ running

Gets the running status

running
Returns
`boolean`: running running status
▸ current

Gets the current task(s)

current
Returns
`(Task | Array<Task>)`: task current task(s)
▸ passed

Gets the passed task(s)

passed
Returns
`Array<Task>`: task passed task(s)
▸ autoRun

Sets autoRun

Will autorun on push or unshift

autoRun
Parameters
value `(any)`
autoRun `(boolean)` auto runs on push or unshift
▸ autoRun

Gets autoRun

autoRun
Returns
`boolean`: autoStart auto start on push or unshift

### Limiter

Limiter

Parallel with limit for max running tasks

new Limiter(limit: number, complete: Function, recover: Function, completeOnFirst: boolean)

Extends Parallel

Parameters
limit `(number)` max running tasks
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
completeOnFirst `(boolean)` completes on last or on first
Instance Members
▸ constructor(limit, complete, recover, completeOnFirst)

Limiter constructor

constructor(limit: number, complete: Function, recover: Function, completeOnFirst: boolean)
Parameters
limit `(number)` max running tasks
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
completeOnFirst `(boolean)` completes on last or on first
▸ _runCondition

Returns the run condition

_runCondition
Returns
`boolean`: condition run condition
▸ _taskComplete()

Performs on every task complete

_taskComplete()

### Loop

Loop

Recurrent tasks

new Loop(repeats: number, repeat: Function, recover: Function)

Extends Sequence

Parameters
repeats `(number)` number of repeats. 0 for infinite
repeat `(Function)` function to be called on repeat
recover `(Function)` function to be called on recover
Instance Members
▸ constructor(repeats, repeat, recover)

Loop constructor

constructor(repeats: number, repeat: Function, recover: Function)
Parameters
repeats `(number)` number of repeats. 0 for infinite
repeat `(Function)` function to be called on repeat
recover `(Function)` function to be called on recover
▸ _complete()

Complete

Runs complete task

_complete()
▸ __next

Gets next task from the loop

__next
Returns
`Task`: task next task
▸ passed

Gets the passed task(s)

passed
Returns
`Array<Task>`: task passed task(s)

### Parallel

Parallel

Executes tasks all at once

new Parallel(complete: Function, recover: Function, completeOnFirst: boolean)

Extends Collection

Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
completeOnFirst `(boolean)` completes on last or on first
Instance Members
▸ constructor(complete, recover, completeOnFirst)

Parallel constructor

constructor(complete: Function, recover: Function, completeOnFirst: boolean)
Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
completeOnFirst `(boolean)` completes on last or on first
▸ run()

Runs all tasks in the collection

run()
▸ _run(task)

Runs a single task

_run(task: any)
Parameters
task `(any)`
▸ _runCondition

Returns the run condition

_runCondition
Returns
`boolean`: condition run condition
▸ _taskComplete()

Performs on every task complete

_taskComplete()
▸ stop(skip)

Stops all tasks in the collection

stop(skip: boolean): boolean
Parameters
skip `(boolean = `false`)` force the stopped task to be skipped
Returns
`boolean`: stopped stopped status
▸ reset()

Resets a stopped collection

reset(): boolean
Returns
`boolean`: reset reset status
▸ current

Gets the current tasks

current
Returns
`Array<Task>`: task current tasks
▸ passed

Gets the passed task(s)

passed
Returns
`Array<Task>`: task passed task(s)

### Sequence

Sequence

Executes tasks one by one

new Sequence(complete: Function, recover: Function)

Extends Collection

Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Instance Members
▸ constructor(complete, recover)

Sequence constructor

constructor(complete: Function, recover: Function)
Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
▸ run()

Runs all tasks in the collection

run()
▸ stop(skip)

Stops all tasks in the collection

stop(skip: boolean): boolean
Parameters
skip `(boolean = `false`)` force the stopped task to be skipped
Returns
`boolean`: stopped stopped status
▸ reset()

Resets a stopped collection

reset(): boolean
Returns
`boolean`: reset reset status
▸ _next()

Runs next in the sequence

_next()
▸ _complete()

Complete

Runs complete task

_complete()
▸ _recover(error)

Recover

Runs recover task

_recover(error: any)
Parameters
error `(any)`
▸ _resetCurrent(unchain, resetAfterComplete)

Resets current

_resetCurrent(unchain: any, resetAfterComplete: any)
Parameters
unchain `(any = `false`)`
resetAfterComplete `(any = `false`)`
▸ __next

Gets next task from the loop

__next
Returns
`Task`: task next task
▸ current

Gets the current task

current
Returns
`Task`: task current task
▸ passed

Gets the passed task(s)

passed
Returns
`Array<Task>`: task passed task(s)

### AsyncMap

Map for AsyncTask

Maps the default ways to get a AsyncTask

new AsyncMap()

Extends Map

Instance Members
▸ match(args, run, complete, recover, marker)

Match argument with a specific TriggerMap

match(args: ...any, run: Function, complete: Function, recover: Function, marker: number): Match
Parameters
args `(...any)`
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
marker `(number)` 0 marks a async task
Returns
`Match`: match

### Factory

Tasks and Collections Factory

It's a static class - do not instantiate with new

new Factory()
Static Members
▸ _CHAIN_

Predefined name for a chain in attached task

_CHAIN_
Parameters
_CHAIN_ `(string)` predefined name
▸ maps

Maps collection for task matching

maps
Parameters
maps `(Array<Map>)` list of all maps
▸ attached

Attached variables

attached
Parameters
attached `(object)` collection of any attachments
▸ initialized

Initialized status

initialized
Parameters
initialized `(boolean)` initialized status
▸ task(args)

Gets a task by registered map match

task(args: any): Task
Parameters
args `(any)` parameters depend on installed maps
Returns
`Task`: task matching the parameters
▸ sequence(complete, recover)

Gets a sequence

sequence(complete: Function, recover: Function): Sequence
Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Returns
`Sequence`: new sequence
▸ parallel(complete, recover, completeOnFirst)

Gets a parallel

parallel(complete: Function, recover: Function, completeOnFirst: boolean): Parallel
Parameters
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
completeOnFirst `(boolean)` completes on last or on first
Returns
`Parallel`: new sequence
▸ loop(repeats, repeat, recover)

Gets a loop

loop(repeats: number, repeat: Function, recover: Function): Loop
Parameters
repeats `(number)` number of repeats, 0 for infinite
repeat `(Function)` function to be called on repeat
recover `(Function)` function to be called on recover
Returns
`Loop`: new loop
▸ limiter(limit, complete, recover, completeOnFirst)

Gets a limiter

limiter(limit: number, complete: Function, recover: Function, completeOnFirst: boolean): Limiter
Parameters
limit `(number)` max running tasks
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
completeOnFirst `(boolean)` completes on last or on first
Returns
`Limiter`: new limiter
▸ initialize(force)

Initializes the factory.

Initializes the factory. Will be called automatically on first task or sequence call. Can be called explicitly with force

initialize(force: boolean)
Parameters
force `(boolean = `false`)` reinitialize if true
▸ map(map)

Adds new map for tasks matching

map(map: Map)
Parameters
map `(Map)` map for tasks matching
▸ unmap(map)

Removes map from tasks matching

unmap(map: Map)
Parameters
map `(Map)` map to remove from tasks matching
▸ unmapAll()

Removes all maps

unmapAll()
▸ attach(key, value)

Attaches variable to the factory

Useful to store your collections and access them later on from anywhere. Or store anything you want in this predefined place

attach(key: string, value: any)
Parameters
key `(string)` accessor for the variable
value `(any)` variable value
▸ detach(key)

Detaches variable by name

detach(key: string)
Parameters
key `(string)` accessor for the variable
▸ get(key)

Gets variable by name

get(key: string): any
Parameters
key `(string)` accessor for the variable
Returns
`any`: variable value

### Map

Map for tasks

Map is used to match parameters with tasks. Every map shall match and return Match class unique for parameters. In case of Match overlapping the one with bigger priority will be selected.

This class is the base for all Map classes. Cannot be used directly. Extend to use.

new Map()
Instance Members
▸ match(args)

Match argument with a specific tasks

match(args: ...any): Match
Parameters
args `(...any)`
Returns
`Match`: match

### Match

Match for a Map

Match contains the instance of the Task and a percentage from 0 to 1. In cases of overlapping of Matches the one with bigger percentage will be used

new Match(instance: Task, percentage: number)
Parameters
instance `(Task)` any Task instance
percentage `(number)` from 0 to 1
Instance Members
▸ constructor(instance, percentage)

Match constructor

constructor(instance: Task, percentage: number)
Parameters
instance `(Task)` any Task instance
percentage `(number)` from 0 to 1
▸ percentage

Percentage setter

percentage
Parameters
value `(number)` from 0 to 1
▸ percentage

Percentage getter

percentage
Returns
`number`: percentage value from 0 to 1

### PromiseMap

Map for PromiseTask

Maps the default ways to get a PromiseTask

new PromiseMap()

Extends Map

Instance Members
▸ match(args, promise, complete, recover)

Match argument with a specific PromiseMap

match(args: ...any, promise: Promise, complete: Function, recover: Function): Match
Parameters
args `(...any)`
promise `(Promise)` promise to wait for
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Returns
`Match`: match

### RawMap

Raw map for Task

Maps the default ways to get a Task

new RawMap()

Extends Map

Instance Members
▸ match(args, run, complete, recover)

Match argument with a specific Task

match(args: ...any, run: Function, complete: Function, recover: Function): Match
Parameters
args `(...any)`
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Returns
`Match`: match

### TimeoutMap

Map for TimeoutTasks

Maps the default ways to get a TimeoutTask

new TimeoutMap()

Extends Map

Instance Members
▸ match(args, timeout, run, complete, recover)

Match argument with a specific TimeoutTask

match(args: ...any, timeout: number, run: Function, complete: Function, recover: Function): Match
Parameters
args `(...any)`
timeout `(number)` timeout in ms
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Returns
`Match`: match

### TriggerMap

Map for TriggerTask

Maps the default ways to get a TriggerTask

new TriggerMap()

Extends Map

Instance Members
▸ match(args, complete, marker)

Match argument with a specific TriggerTask

match(args: ...any, complete: Function, marker: boolean): Match
Parameters
args `(...any)`
complete `(Function)` function to be called on complete
marker `(boolean)` false marks a trigger task
Returns
`Match`: match

### AsyncTask

AsyncTask

Executes run and does not complete automatically. Need manual call of complete() method. Useful for triggers.

Similar with TriggerTask, but with full set of run, complete and recover. In run method first parameter will be complete callback, second self and ...args to follow. Does not care what run returns.

new AsyncTask(run: Function, complete: Function, recover: Function)

Extends Task

Parameters
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Example

    run = (complete, self, ...args) => { complete(); }

Instance Members
▸ constructor(run, complete, recover)

AsyncTask constructor

constructor(run: Function, complete: Function, recover: Function)
Parameters
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
▸ run(args)

Runs a task

Executes the run function if defined. All arguments will be passed to it.

run(args: any)
Parameters
args `(any)` any arguments

### Injector

Injector. Internal class

Injects functions into objects. Used internally. Not intended to be used on it's own.

new Injector()
Static Members
▸ afterComplete(task, callback, key)

Appends a function after complete and remembers the original

afterComplete(task: Task, callback: Function, key: String): Task
Parameters
task `(Task)` task to be modified
callback `(Function)` function to be called after complete
key `(String)` map for the original callback
Returns
`Task`: task modified task
▸ resetAfterComplete(task, key)

Resets the complete method to it's original state

resetAfterComplete(task: Task, key: String): Task
Parameters
task `(Task)` task to be modified
key `(String)` map for the original callback
Returns
`Task`: task modified task
▸ addChainGetter(task)

Adds a method called chain to get Factory.CHAIN

Shortcut for task.get(Factory.CHAIN)

addChainGetter(task: Task): Task
Parameters
task `(Task)` task to be modified
Returns
`Task`: task modified task
▸ removeChainGetter(task)

Remove a method called chain to get Factory.CHAIN

removeChainGetter(task: Task): Task
Parameters
task `(Task)` task to be modified
Returns
`Task`: task modified task

### PromiseTask

PromiseTask

Takes a Promise and waits for it to complete. Will attack to finally and complete. Useful for triggers.

Similar with TriggerTask, but with set of complete and recover.

new PromiseTask(promise: Promise, complete: Function, recover: Function)

Extends Task

Parameters
promise `(Promise)` promise instance to wait for
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Instance Members
▸ constructor(promise, complete, recover)

PromiseTask constructor

constructor(promise: Promise, complete: Function, recover: Function)
Parameters
promise `(Promise)` promise instance to wait for
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
▸ run(args)

Runs a task

Checks if promise already resolved. If not does nothing.

run(args: any)
Parameters
args `(any)` any arguments
▸ _isPromise(promise)

Checks if instance is Promise

We do not want promises as a dependency - as it's conditionally used. The checks for promise will be a bit loose - just checking for finally and assuming it's a Promise.

_isPromise(promise: Promise): boolean
Parameters
promise `(Promise)` promise instance
Returns
`boolean`:
▸ _setPromise(promise)

Sets promise and attaches to finally

_setPromise(promise: Promise)
Parameters
promise `(Promise)` promise instance
▸ _promiseFinally()

Handles promise finally resolved

_promiseFinally()

### Task

Task

Basic task with run, complete and recover

run function can return nothing(undefined) and it will call complete instantly. if run returns anything it will NOT call complete automatically and it's up to you to trigger complete.

new Task(run: Function, complete: Function, recover: Function)
Parameters
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Example

    run = () => { console.log('next thing is complete'); }

    run = (self) => {
      console.log('will manually call complete()');
      // some logic to call self.complete() later
      // or call complete() from outside to make a trigger waiter
      return 1; // or whatever you want but undefined
    }

Instance Members
▸ constructor(run, complete, recover)

Task constructor

constructor(run: Function, complete: Function, recover: Function)
Parameters
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
▸ attach(key, value)

Attaches variable to the task

attach(key: string, value: any)
Parameters
key `(string)` accessor for the variable
value `(any)` variable value
▸ detach(key)

Detaches variable by name

detach(key: string)
Parameters
key `(string)` accessor for the variable
▸ get(key)

Gets variable by name

get(key: string): any
Parameters
key `(string)` accessor for the variable
Returns
`any`: variable value
▸ run(args)

Runs a task

Executes the run function if defined. All arguments will be passed to it.

run(args: any)
Parameters
args `(any)` any arguments
▸ complete(args)

Completes a task

Executes the complete function if defined. All arguments will be passed to it.

complete(args: any)
Parameters
args `(any)` any arguments
▸ recover(args)

Recovers a task

Executes the recover function if defined. All arguments will be passed to it.

recover(args: any)
Parameters
args `(any)` any arguments
▸ stop()

Stops a task

stop(): boolean
Returns
`boolean`: success
▸ restart(args)

Restarts a task

If stopped will start it If running will respect stop()

restart(args: ...any): boolean
Parameters
args `(...any)`
Returns
`boolean`: success
▸ running

Gets the running status

running
Returns
`boolean`: running
▸ done

Gets the done status

done
Returns
`boolean`: done
▸ failed

Gets the failed status

failed
Returns
`boolean`: failed
▸ exceptions

Gets the exceptions if any

exceptions
Returns
`Object`: exceptions

### TimeoutTask

TimeoutTask

Timeout task with run, complete and recover. Executes after initial timeout

new TimeoutTask(timeout: number, run: Function, complete: Function, recover: Function)

Extends Task

Parameters
timeout `(number)` wait before run
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
Instance Members
▸ constructor(timeout, run, complete, recover)

TimeoutTask constructor

constructor(timeout: number, run: Function, complete: Function, recover: Function)
Parameters
timeout `(number)` wait before run
run `(Function)` function to be called on run
complete `(Function)` function to be called on complete
recover `(Function)` function to be called on recover
▸ run(args)

Runs a task

Executes the run function if defined. All arguments will be passed to it.

run(args: any)
Parameters
args `(any)` any arguments
▸ complete(args)

Completes a task

Executes the complete function if defined. All arguments will be passed to it.

complete(args: any)
Parameters
args `(any)` any arguments
▸ stop()

Stops a task

stop(): boolean
Returns
`boolean`: success

### TriggerTask

TriggerTask

Trigger task with complete. Executes run and does not complete automatically. Need manual call of complete() method. Useful for triggers.

new TriggerTask(complete: Function)

Extends Task

Parameters
complete `(Function)` function to be called on complete
Instance Members
▸ constructor(complete)

TriggerTask constructor

constructor(complete: Function)
Parameters
complete `(Function)` function to be called on complete
▸ run(args)

Runs a task

Executes the run function if defined. All arguments will be passed to it.

run(args: any)
Parameters
args `(any)` any arguments