Places the function to be executed in the internal task queue of the task pool. The function will be distributed to the worker thread for execution. The function to be executed in this mode cannot be canceled.
| func | Function | Yes | Function to be executed. For details about the supported return value types of the function, see [Sequenceable Data Types](#sequenceable-data-types). |
| args | unknown[] | No | Arguments of the function. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types). The default value is **undefined**.|
Places a task in the internal task queue of the task pool. The task will be distributed to the worker thread for execution. The task to be executed in this mode can be canceled.
| function | Function | Yes | Yes | Function to be passed in during task creation. For details about the supported return value types of the function, see [Sequenceable Data Types](#sequenceable-data-types). |
| arguments | unknown[] | Yes | Yes | Arguments of the function. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
## TaskGroup<sup>10+</sup>
Implements a task group. Before using any of the following APIs, you must create a **TaskGroup** instance.
### constructor<sup>10+</sup>
constructor()
Constructor used to create a **TaskGroup** instance.
| func | Function | Yes | Function to be passed in for task execution. For details about the supported return value types of the function, see [Sequenceable Data Types](#sequenceable-data-types). |
| args | unknown[] | No | Arguments of the function. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types). The default value is **undefined**.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
Places the function to be executed in the internal task queue of the task pool. The function will be distributed to the worker thread for execution. The function to be executed in this mode cannot be canceled.
| function | Function | Yes | Yes | Function to be passed in during task creation. For details about the supported return value types of the function, see [Sequenceable Data Types](#sequenceable-data-types). |
| arguments | unknown[] | Yes | Yes | Arguments of the function. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| func | Function | Yes | Function to be executed. For details about the supported return value types of the function, see [Sequenceable Data Types](#sequenceable-data-types). |
| args | unknown[] | No | Arguments of the function. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types). The default value is **undefined**.|
## TaskGroup<sup>10+</sup>
**Return value**
Implements a task group. Before calling any APIs in **TaskGroup**, you must use [constructor](#constructor10) to create a **TaskGroup** instance.
Places a task in the internal task queue of the task pool. The task will be distributed to the worker thread for execution. The task to be executed in this mode can be canceled.
Adds the function to be executed to this task group. Before using this API, you must create a **TaskGroup** instance.
| func | Function | Yes | Function to be passed in for task execution. For details about the supported return value types of the function, see [Sequenceable Data Types](#sequenceable-data-types). |
| args | unknown[] | No | Arguments of the function. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types). The default value is **undefined**.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| state | [State](#state10) | Yes | No | Task state. |
| duration | number | Yes | No | Duration that the task has been executed, in ms. If the return value is **0**, the task is not running. If the return value is empty, no task is running. |
lettask1=newtaskpool.Task(inspectStatus,100);// 100: test number
lettask2=newtaskpool.Task(inspectStatus,200);// 200: test number
lettask3=newtaskpool.Task(inspectStatus,300);// 300: test number
lettask4=newtaskpool.Task(inspectStatus,400);// 400: test number
lettask5=newtaskpool.Task(inspectStatus,500);// 500: test number
lettask6=newtaskpool.Task(inspectStatus,600);// 600: test number
taskpool.execute(task1).then((res)=>{
console.log("taskpool test result: "+res);
}).catch((err)=>{
console.log("taskpool test occur error: "+err);
});
letres2=taskpool.execute(task2);
letres3=taskpool.execute(task3);
letres4=taskpool.execute(task4);
letres5=taskpool.execute(task5);
letres6=taskpool.execute(task6);
// Cancel the task 1s later.
setTimeout(()=>{
taskpool.cancel(task1);},1000);
```
## ThreadInfo<sup>10+</sup>
## taskpool.cancel<sup>10+</sup>
Describes the internal information about a worker thread.