Collection
Collection. Abstract class.
Basic collection class. Do NOT instantiate directly.
Parameters
complete (Function)
function to be called on complete
recover (Function)
function to be called on recover
Instance Members
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
Detaches variable with a key
Parameters
key (string)
accessor for the variable
Gets variable with a key
Parameters
key (string)
accessor for the variable
Returns
any
:
value variable value
Pushes task to the collection
Parameters
Returns
Collection
:
collection current collection
Unshifts task to the collection
Parameters
Returns
Collection
:
collection current collection
Removes task from the collection
Parameters
Returns
Collection
:
collection current collection
Runs all tasks in the collection
run()
Stops all tasks in the collection
Returns
boolean
:
stopped stopped status
Resets a stopped collection
Returns
boolean
:
reset reset status
Complete
Runs complete task
_complete()
Recover
Runs recover task
_recover(error: any)
Parameters
Chain task
Attach the chain to the task
Parameters
task (Task)
task to chain
Unchain task
Detach the chain from the task
Parameters
task (Task)
task to chain
Probe post add actions
Try all post add triggers
_postTaskAdds()
Gets the running status
running
Returns
boolean
:
running running status
Gets the current task(s)
current
Returns
(Task | Array<Task>)
:
task current task(s)
Gets the passed task(s)
passed
Returns
Array<Task>
:
task passed task(s)
Sets autoRun
Will autorun on push or unshift
autoRun
Parameters
autoRun (boolean)
auto runs on push or unshift
Gets autoRun
autoRun
Returns
boolean
:
autoStart auto start on push or unshift
Limiter
Limiter
Parallel with limit for max running tasks
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
Returns the run condition
_runCondition
Returns
boolean
:
condition run condition
Performs on every task complete
_taskComplete()
Loop
Loop
Recurrent tasks
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
Complete
Runs complete task
_complete()
Gets next task from the loop
__next
Returns
Task
:
task next task
Gets the passed task(s)
passed
Returns
Array<Task>
:
task passed task(s)
Parallel
Parallel
Executes tasks all at once
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
Runs all tasks in the collection
run()
Runs a single task
_run(task: any)
Parameters
Returns the run condition
_runCondition
Returns
boolean
:
condition run condition
Performs on every task complete
_taskComplete()
Stops all tasks in the collection
Parameters
skip (boolean
= false
)
force the stopped task to be skipped
Returns
boolean
:
stopped stopped status
Resets a stopped collection
Returns
boolean
:
reset reset status
Gets the current tasks
current
Returns
Array<Task>
:
task current tasks
Gets the passed task(s)
passed
Returns
Array<Task>
:
task passed task(s)
Sequence
Sequence
Executes tasks one by one
Extends
Collection
Parameters
complete (Function)
function to be called on complete
recover (Function)
function to be called on recover
Instance Members
Runs all tasks in the collection
run()
Stops all tasks in the collection
Parameters
skip (boolean
= false
)
force the stopped task to be skipped
Returns
boolean
:
stopped stopped status
Resets a stopped collection
Returns
boolean
:
reset reset status
Runs next in the sequence
_next()
Complete
Runs complete task
_complete()
Recover
Runs recover task
_recover(error: any)
Parameters
▸
_resetCurrent(unchain, resetAfterComplete)
Resets current
_resetCurrent(unchain: any, resetAfterComplete: any)
Parameters
resetAfterComplete (any
= false
)
Gets next task from the loop
__next
Returns
Task
:
task next task
Gets the current task
current
Returns
Task
:
task current task
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
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
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
Predefined name for a chain in attached task
_CHAIN_
Parameters
_CHAIN_ (string)
predefined name
Maps collection for task matching
maps
Parameters
Attached variables
attached
Parameters
attached (object)
collection of any attachments
Initialized status
initialized
Parameters
initialized (boolean)
initialized status
Gets a task by registered map match
Parameters
args (any)
parameters depend on installed maps
Returns
Task
:
task matching the parameters
▸
sequence(complete, recover)
Gets a 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
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
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
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
Initializes the factory.
Initializes the factory. Will be called automatically on first task
or sequence call. Can be called explicitly with force
Parameters
force (boolean
= false
)
reinitialize if true
Adds new map for tasks matching
Parameters
map (Map)
map for tasks matching
Removes map from tasks matching
Parameters
map (Map)
map to remove from tasks matching
Removes all maps
unmapAll()
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
Detaches variable by name
Parameters
key (string)
accessor for the variable
Gets variable by name
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 argument with a specific tasks
match(args: ...any):
Match
Parameters
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
Parameters
instance (Task)
any Task instance
percentage (number)
from 0 to 1
Instance Members
Percentage setter
percentage
Parameters
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
Parameters
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
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
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
Parameters
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
Parameters
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.
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
Runs a task
Executes the run function if defined. All arguments will be
passed to it.
run(args: any)
Parameters
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
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
Parameters
task (Task)
task to be modified
key (String)
map for the original callback
Returns
Task
:
task modified task
Adds a method called chain to get Factory.CHAIN
Shortcut for task.get(Factory.CHAIN)
Parameters
task (Task)
task to be modified
Returns
Task
:
task modified task
▸
removeChainGetter(task)
Remove a method called chain to get Factory.CHAIN
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.
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
Runs a task
Checks if promise already resolved. If not does nothing.
run(args: any)
Parameters
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.
Parameters
Returns
boolean
:
Sets promise and attaches to finally
Parameters
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.
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()');
return 1;
}
Instance Members
Attaches variable to the task
attach(key:
string, value: any)
Parameters
key (string)
accessor for the variable
value (any)
variable value
Detaches variable by name
Parameters
key (string)
accessor for the variable
Gets variable by name
Parameters
key (string)
accessor for the variable
Returns
any
:
variable value
Runs a task
Executes the run function if defined. All arguments will be
passed to it.
run(args: any)
Parameters
Completes a task
Executes the complete function if defined. All arguments will be
passed to it.
complete(args: any)
Parameters
Recovers a task
Executes the recover function if defined. All arguments will be
passed to it.
recover(args: any)
Parameters
Stops a task
Returns
boolean
:
success
Restarts a task
If stopped will start it
If running will respect stop()
Parameters
Returns
boolean
:
success
Gets the running status
running
Returns
boolean
:
running
Gets the done status
done
Returns
boolean
:
done
Gets the failed status
failed
Returns
boolean
:
failed
Gets the exceptions if any
exceptions
Returns
Object
:
exceptions
TimeoutTask
TimeoutTask
Timeout task with run, complete and recover.
Executes after initial timeout
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
Runs a task
Executes the run function if defined. All arguments will be
passed to it.
run(args: any)
Parameters
Completes a task
Executes the complete function if defined. All arguments will be
passed to it.
complete(args: any)
Parameters
Stops a task
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.
Extends
Task
Parameters
complete (Function)
function to be called on complete
Instance Members
Runs a task
Executes the run function if defined. All arguments will be
passed to it.
run(args: any)
Parameters