Operations and Tasks are Total's features which can be used in many different cases. Operation is something like global function in your app but with some extra functionality. Task has multiple smaller functions which can be called separatly from that task or even outside of that task. You can even chain them inside single task to create complex recursive flows.
Operations are global functions with some extra functionality. They are often used as alternative way to handle client requests or used as wrappers.
Operations are usually stored in
operations directory inside root of your application. To declare new operation you need to use global function
NEWOPERATION(). Function takes two required and four optional arguments:
$that will be executed when operation is called .
CONVERT()on background. Converted values are stored in
To make operation un-successful (throw error in callback) you can use
After declaring your operation you can simply execute it with
OPERATION(). Function has two required and three optional arguments:
You can also call operation directly from your
To run multiple operations in your code you can use global function
RUN(). This function has two required and four optional arguments:
RUN() function support multiple declaration syntaxes for operations:
$.valuein each operation.
Response value in your callback function will be an object of all operation's responses. If you want only specific response you can name of that operation as fourth argument:
After user hits
GET /operations/ route, operations
third will be executed and user will get response (or error) from
second operation because it has
Tasks are very versatile because they can execute infinitely between themself. Tasks are great solution for your simple or complex processes.
All tasks are usually stored in
tasks directory inside root of your Total.js application. To declare new operation use global function
pushargument that is used for adding more "steps" to your task.
$ methods for tasks:
$.end(value)- Ends task and execute callback declared with
$.end(value)wrapped in function (use this as callback function).
$.next(step)- Call next task "step".
$.next(step)wrapped in function (use this as callback function).
$.invalid()are also valid methods in task builder.
To execute your tasks use global function
responseobjects (depends on task's result). Callback is called after executing
$.end()method in your task.