@@ -22,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
|AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
**Error codes**
...
...
@@ -59,9 +59,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
**Error codes**
...
...
@@ -94,9 +94,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
**Error codes**
...
...
@@ -128,9 +128,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters**
| Type| Description|
| -------- | -------- |
| AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
**Error codes**
...
...
@@ -164,9 +164,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
**Error codes**
...
...
@@ -198,9 +198,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback<number> |Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
| Type| Description|
| -------- | -------- |
|AsyncCallback<number> |Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
| bundleName | string | Yes | Bundle name of the shared library.|
| versionCode | number | Yes | Version number of the shared library. |
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.|
| bundleName | string | Yes | Bundle name of the shared library.|
| versionCode | number | Yes | Version number of the shared library. |
**Return value**
| Type| Description|
| -------- | -------- |
|AsyncCallback\<boolean>> | Callback used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.|
@@ -641,7 +717,7 @@ Obtains applications that are running in the foreground. This API uses a promise
| Type| Description|
| -------- | -------- |
| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return an array holding the application state data.|
| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return an array holding the application state data.|
**Error codes**
...
...
@@ -731,11 +807,11 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
Publishes a reminder through the reminder agent. This API uses an asynchronous callback to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8).
...
...
@@ -39,7 +37,7 @@ Publishes a reminder through the reminder agent. This API uses an asynchronous c
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | Yes| Reminder to be published.|
| callback | AsyncCallback\<number\> | Yes| Callback used to return the published reminder's ID.|
| callback | AsyncCallback\<number> | Yes| Callback used to return the published reminder's ID.|
**Example**
```ts
...
...
@@ -56,9 +54,7 @@ Publishes a reminder through the reminder agent. This API uses an asynchronous c
Publishes a reminder through the reminder agent. This API uses a promise to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8).
...
...
@@ -78,7 +74,7 @@ Publishes a reminder through the reminder agent. This API uses a promise to retu
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<number\> | Promise used to return the published reminder's ID.|
| Promise\<number> | Promise used to return the published reminder's ID.|
**Example**
```ts
...
...
@@ -95,9 +91,7 @@ Publishes a reminder through the reminder agent. This API uses a promise to retu
Obtains all valid (not yet expired) reminders set by the current application. This API uses an asynchronous callback to return the reminders.
...
...
@@ -175,7 +165,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)\>\> | Yes| Callback used to return an array of all valid reminders set by the current application.|
| callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)>> | Yes| Callback used to return an array of all valid reminders set by the current application.|
| repeatMonths | Array\<number\> | No| Month in which the reminder repeats.|
| repeatDays | Array\<number\> | No| Date on which the reminder repeats.|
| repeatMonths | Array\<number> | No| Month in which the reminder repeats.|
| repeatDays | Array\<number> | No| Date on which the reminder repeats.|
## ReminderRequestAlarm<sup>(deprecated)</sup>
ReminderRequestAlarm extends ReminderRequest
Defines a reminder for an alarm.
...
...
@@ -601,13 +575,11 @@ Defines a reminder for an alarm.
| -------- | -------- | -------- | -------- |
| hour | number | Yes| Hour portion of the reminder time.|
| minute | number | Yes| Minute portion of the reminder time.|
| daysOfWeek | Array\<number\> | No| Days of a week when the reminder repeats. The value ranges from 1 to 7, corresponding to the data from Monday to Sunday.|
| daysOfWeek | Array\<number> | No| Days of a week when the reminder repeats. The value ranges from 1 to 7, corresponding to the data from Monday to Sunday.|
@@ -170,7 +170,7 @@ Cancels the reminder with the specified ID. This API uses a promise to return th
| Type| Description|
| -------- | -------- |
| PPromise\<void> | Promise used to return the result.|
| Promise\<void> | Promise used to return the result.|
**Error codes**
...
...
@@ -611,7 +611,7 @@ Defines the reminder to publish.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| reminderType | [ReminderType](#remindertype) | Yes| Type of the reminder.|
| actionButton<sup>10+</sup> | [ActionButton](#actionbutton) | No| Button displayed for the reminder in the notification panel. For common applications, a maximum of two buttons are supported. For system applications, a maximum of two buttons are supported in API version 9, and a maximum of three buttons are supported in API version 10 and later versions.|
| actionButton<sup>10+</sup> | [ActionButton](#actionbutton) | No| Button displayed for the reminder in the notification panel. For common applications, a maximum of two buttons are supported. For system applications, a maximum of two buttons are supported in API version 9, and a maximum of three buttons are supported in API version 10 and later versions.|
| wantAgent | [WantAgent](#wantagent) | No| Information about the ability that is redirected to when the reminder is clicked.|
| maxScreenWantAgent | [MaxScreenWantAgent](#maxscreenwantagent) | No| Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.|
| ringDuration | number | No| Ringing duration, in seconds. The default value is **1**.|
The task pool provides a multi-thread running environment for applications. It helps reduce resource consumption and improve system performance. It also frees you from caring about the lifecycle of thread instances. You can use the **TaskPool** APIs to create background tasks and perform operations on them, for example, executing or canceling a task. Theoretically, you can create an unlimited number of tasks, but this is not recommended for memory considerations. In addition, you are not advised performing blocking operations in a task, especially indefinite blocking. Long-time blocking operations occupy worker threads and may block other task scheduling, adversely affecting your application performance.
You can determine the execution sequence of tasks with the same priority. They are executed in the same sequence as you call the task execution APIs. The default task priority is **MEDIUM**. (The task priority mechanism is not supported yet.)
You can determine the execution sequence of tasks with the same priority. They are executed in the same sequence as you call the task execution APIs. The default task priority is **MEDIUM**.
If the number of tasks to be executed is greater than the number of worker threads in the task pool, the task pool scales out based on load balancing to minimize the waiting duration. Similarly, when the number of tasks to be executed falls below the number of worker threads, the task pool scales in to reduce the number of worker threads. (The load balancing mechanism is not supported yet.)
If the number of tasks to be executed is greater than the number of worker threads in the task pool, the task pool scales out based on load balancing to minimize the waiting duration. Similarly, when the number of tasks to be executed falls below the number of worker threads, the task pool scales in to reduce the number of worker threads.
The **TaskPool** APIs return error codes in numeric format. For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
...
...
@@ -32,13 +32,13 @@ Enumerates the priorities available for created tasks.
**Example**
```ts
functionfunc(args){
"use concurrent";
console.log("func: "+args);
@Concurrent
functionprintArgs(args){
console.log("printArgs: "+args);
returnargs;
}
asyncfunctiontaskpoolTest(){
lettask=newtaskpool.Task(func,100);
asyncfunctiontaskpoolPriority(){
lettask=newtaskpool.Task(printArgs,100);
lethighCount=0;
letmediumCount=0;
...
...
@@ -65,7 +65,7 @@ async function taskpoolTest() {
})
}
}
taskpoolTest();
taskpoolPriority();
```
## Task
...
...
@@ -99,12 +99,12 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
@Concurrent
functionfunc(args){
console.log("func: "+args);
functionprintArgs(args){
console.log("printArgs: "+args);
returnargs;
}
lettask=newtaskpool.Task(func,"this is my first Task");
lettask=newtaskpool.Task(printArgs,"this is my first Task");
```
### Attributes
...
...
@@ -151,17 +151,17 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
@Concurrent
functionfunc(args){
console.log("func: "+args);
functionprintArgs(args){
console.log("printArgs: "+args);
returnargs;
}
asyncfunctiontaskpoolTest(){
letvalue=awaittaskpool.execute(func,100);
asyncfunctiontaskpoolExecute(){
letvalue=awaittaskpool.execute(printArgs,100);
console.log("taskpool result: "+value);
}
taskpoolTest();
taskpoolExecute();
```
## taskpool.execute
...
...
@@ -199,18 +199,18 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
@Concurrent
functionfunc(args){
console.log("func: "+args);
functionprintArgs(args){
console.log("printArgs: "+args);
returnargs;
}
asyncfunctiontaskpoolTest(){
lettask=newtaskpool.Task(func,100);
asyncfunctiontaskpoolExecute(){
lettask=newtaskpool.Task(printArgs,100);
letvalue=awaittaskpool.execute(task);
console.log("taskpool result: "+value);
}
taskpoolTest();
taskpoolExecute();
```
## taskpool.cancel
...
...
@@ -239,14 +239,14 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
**Example of successful task cancellation**
```ts
functionfunc(args){
"use concurrent";
console.log("func: "+args);
@Concurrent
functionprintArgs(args){
console.log("printArgs: "+args);
returnargs;
}
asyncfunctiontaskpoolTest(){
lettask=newtaskpool.Task(func,100);
asyncfunctiontaskpoolCancel(){
lettask=newtaskpool.Task(printArgs,100);
taskpool.execute(task);
try{
taskpool.cancel(task);
...
...
@@ -255,20 +255,20 @@ async function taskpoolTest() {
}
}
taskpoolTest();
taskpoolCancel();
```
**Example of a failure to cancel a task that has been executed**
```ts
functionfunc(args){
"use concurrent";
console.log("func: "+args);
@Concurrent
functionprintArgs(args){
console.log("printArgs: "+args);
returnargs;
}
asyncfunctiontaskpoolTest(){
lettask=newtaskpool.Task(func,100);
asyncfunctiontaskpoolCancel(){
lettask=newtaskpool.Task(printArgs,100);
letvalue=taskpool.execute(task);
letstart=newDate().getTime();
while(newDate().getTime()-start<1000){// Wait for 1s to ensure that the task has been executed.
...
...
@@ -282,25 +282,25 @@ async function taskpoolTest() {
}
}
taskpoolTest();
taskpoolCancel();
```
**Example of a failure to cancel an ongoing task**
```ts
functionfunc(args){
"use concurrent";
console.log("func: "+args);
@Concurrent
functionprintArgs(args){
console.log("printArgs: "+args);
returnargs;
}
asyncfunctiontaskpoolTest(){
lettask1=newtaskpool.Task(func,100);
lettask2=newtaskpool.Task(func,200);
lettask3=newtaskpool.Task(func,300);
lettask4=newtaskpool.Task(func,400);
lettask5=newtaskpool.Task(func,500);
lettask6=newtaskpool.Task(func,600);
asyncfunctiontaskpoolCancel(){
lettask1=newtaskpool.Task(printArgs,100);
lettask2=newtaskpool.Task(printArgs,200);
lettask3=newtaskpool.Task(printArgs,300);
lettask4=newtaskpool.Task(printArgs,400);
lettask5=newtaskpool.Task(printArgs,500);
lettask6=newtaskpool.Task(printArgs,600);
letres1=taskpool.execute(task1);
letres2=taskpool.execute(task2);
...
...
@@ -315,7 +315,7 @@ async function taskpoolTest() {
}
}
taskpoolTest();
taskpoolCancel();
```
## Additional Information
...
...
@@ -327,7 +327,7 @@ The following sequenceable data types are supported: All Primitive Type (excludi
- The task pool APIs can be used only in the module with **compileMode** set to **esmodule** in the stage model. To check the **compileMode** setting of a module, open the **build-profile.json5** file of the module and check for **"compileMode": "esmodule"** under **buildOption**.
- A task in the task pool can reference only variables passed in by input parameters or imported variables, rather than closure variables. The decorator **@Concurrent** is used to intercept unsupported variables.
- A task in the task pool supports only common functions or async functions, rather than class member functions or anonymous functions. The decorator **@Concurrent** is used to intercept unsupported functions.
- The decorator **@Concurrent** can be used only in the .ets file. To create a task in the task pool in the .ts file, use the statement **use concurrent**.
- The decorator **@Concurrent** can be used only in .ets files.
### Using the Task Pool in Simple Mode
...
...
@@ -336,23 +336,23 @@ The following sequenceable data types are supported: All Primitive Type (excludi
```ts
// Common functions are supported, and variables passed in by input parameters are also supported.
@Concurrent
functionfunc(args){
functionprintArgs(args){
console.log("func: "+args);
returnargs;
}
asyncfunctiontaskpoolTest(){
asyncfunctiontaskpoolExecute(){
// taskpool.execute(task)
lettask=newtaskpool.Task(func,"create task, then execute");
lettask=newtaskpool.Task(printArgs,"create task, then execute");