| ABILITY_NOT_RESPONDING | 1 | The ability does not respond.|
| NORMAL | 2 | The ability exits normally.|
| ABILITY_NOT_RESPONDING | 1 | The ability does not respond. This enum is supported since API version 9 and deprecated since API version 10. You are advised to use **APP_FREEZE**.|
| NORMAL | 2 | The ability exits normally because the user closes the application.|
| CPP_CRASH<sup>10+</sup> | 3 | The ability exits due to abnormal signals on the local host.|
| JS_ERROR<sup>10+</sup> | 4 | The ability exits due to a JS_ERROR fault triggered when an application has a JS syntax error that is not captured by developers.|
| APP_FREEZE<sup>10+</sup> | 5 | The ability exits because watchdog detects that the application is frozen.|
| PERFORMANCE_CONTROL<sup>10+</sup> | 6 | The ability exits due to system performance problems, for example, insufficient device memory.|
| RESOURCE_CONTROL<sup>10+</sup> | 7 | The ability exits because the system resource usage (CPU, I/O, or memory usage) exceeds the upper limit.|
| UPGRADE<sup>10+</sup> | 8 | The ability exits due to an update.|
**Example**
...
...
@@ -218,3 +224,24 @@ class MyAbility extends UIAbility {
}
}
```
## AbilityConstant.ContinueState<sup>10+</sup>
Enumerates the mission continuation states of the application. It is used in the [setMissionContinueState](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextsetmissioncontinuestate10) API of [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md).
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
...
...
@@ -115,7 +116,7 @@ Enumerates the types of Extension abilities.
| PRINT<sup>10+</sup> | 15 | PrintExtensionAbility: provides APIs for printing images. Printing documents is not supported yet.|
| PUSH<sup>10+</sup> | 17 | PushExtensionAbility: provides APIs for pushing scenario-specific messages. This ability is reserved.|
| DRIVER<sup>10+</sup> | 18 | DriverExtensionAbility: provides APIs for the peripheral driver. This type of ability is not supported yet.|
| APP_ACCOUNT_AUTHORIZATION<sup>10+</sup> | 19 | AuthorizationExtensionAbility: provides APIs to process authorization requests for application accounts and allow account authorization from a third-party (relative to the operating system vendor) ecosystem platform.|
| APP_ACCOUNT_AUTHORIZATION<sup>10+</sup> | 19 | [AuthorizationExtensionAbility](js-apis-appAccount-authorizationExtensionAbility.md): provides APIs to process authorization requests for application accounts and allow account authorization from a third-party (relative to the operating system vendor) ecosystem platform.|
| UNSPECIFIED | 255 | No type is specified. It is used together with **queryExtensionAbilityInfo** to query all types of Extension abilities.|
...
...
@@ -677,7 +678,7 @@ Obtains the information about all bundles based on the given bundle flags and us
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability. |
| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the ability.|
| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the application.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes**
...
...
@@ -1814,7 +1815,7 @@ Enables or disables an ability. This API uses a promise to return the result.
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability. |
| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the ability.|
| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the application.|
Obtains the distribution type of a bundle in synchronous mode. The return value is the **specifiedDistributionType** field value in [InstallParam](./js-apis-installer.md#installparam) passed when **install** is called.
Obtains additional information about a bundle in synchronous mode. The return value is the **additionalInfo** field value in [InstallParam](./js-apis-installer.md#installparam) passed when **install** is called.
| boolean | Returns **true** if the running task is canceled; returns **false** otherwise.|
**Example**
```ts
@Concurrent
functioninspectStatus(arg){
// do something
if(taskpool.Task.isCanceled()){
console.log("task has been canceled.");
// do something
returnarg+1;
}
// do something
returnarg;
}
```
> **NOTE**
>
> **isCanceled** must be used together with **taskpool.cancel**. If **cancel** is not called, **isCanceled** returns **false** by default.
**Example**
```ts
@Concurrent
functioninspectStatus(arg){
// Check the cancellation status and return the result.
if(taskpool.Task.isCanceled()){
console.log("task has been canceled before 2s sleep.");
returnarg+2;
}
// Wait for 2s.
lett=Date.now();
while(Date.now()-t<2000){
continue;
}
// Check the cancellation status again and return the result.
if(taskpool.Task.isCanceled()){
console.log("task has been canceled after 2s sleep.");
returnarg+3;
}
returnarg+1;
}
lettask=newtaskpool.Task(inspectStatus,100);// 100: test number
taskpool.execute(task).then((res)=>{
console.log("taskpool test result: "+res);
}).catch((err)=>{
console.log("taskpool test occur error: "+err);
});
// If cancel is not called, isCanceled() returns false by default, and the task execution result is 101.
```
### setTransferList<sup>10+</sup>
setTransferList(transfer?: ArrayBuffer[]): void
Sets the task transfer list.
> **NOTE**
>
> This API is used to set the task transfer list in the form of **ArrayBuffer** in the task pool. The **ArrayBuffer** instance does not copy the content in the task to the worker thread during transfer. Instead, it transfers the buffer control right to the worker thread. After the transfer, the **ArrayBuffer** instance becomes invalid.
@@ -116,6 +224,96 @@ let task = new taskpool.Task(printArgs, "this is my first Task");
| 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).
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
Used by the host thread to send a message to the worker thread by transferring object ownership.
| message | Object | Yes | Message to be sent to the worker thread. |
| transfer | ArrayBuffer[] | Yes | An **ArrayBuffer** object can be transferred. The value **null** should not be passed in the array.|
| message | Object | Yes | Data to be sent to the worker thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| transfer | ArrayBuffer[] | Yes | **ArrayBuffer** instance holding an array of objects for which the ownership is transferred to the worker thread. After the transfer, the objects are available only in the worker thread. The array cannot be null.|
**Error codes**
...
...
@@ -181,7 +181,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
Used by the host thread to send a message to the worker thread by transferring object ownership or copying data.
| message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The default value is **undefined**.|
| message | Object | Yes | Data to be sent to the worker thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| options | [PostMessageOptions](#postmessageoptions) | No | If this parameter is specified, it functions the same as **ArrayBuffer[]**. Specifically, the ownership of the objects in the array is transferred to the worker thread and becomes unavailable in the host thread. The objects are available only in the worker thread.<br>If this parameter is not specified, the default value **undefined** is used, and information is transferred to the worker thread by copying data.|
**Error codes**
...
...
@@ -214,7 +214,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
| message | Object | Yes | Data to be sent to the host thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| transfer | ArrayBuffer[] | Yes | **ArrayBuffer** instance holding an array of objects for which the ownership is transferred to the host thread. After the transfer, the objects are available only in the host thread. The array cannot be null.|
**Error codes**
...
...
@@ -867,7 +867,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
| message | Object | Yes | Message to be sent to the host thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The default value is **undefined**.|
| message | Object | Yes | Data to be sent to the host thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| options | [PostMessageOptions](#postmessageoptions) | No | If this parameter is specified, it functions the same as **ArrayBuffer[]**. Specifically, the ownership of the objects in the array is transferred to the host thread and becomes unavailable in the worker thread. The objects are available only in the host thread.<br>If this parameter is not specified, the default value **undefined** is used, and information is transferred to the host thread by copying data.|
**Error codes**
...
...
@@ -915,7 +915,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
Used by the host thread to send a message to the worker thread by transferring object ownership.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorker.postMessage<sup>9+</sup>](#postmessage9) instead.
...
...
@@ -1268,9 +1268,9 @@ Sends a message to the worker thread. The data type of the message must be seque
| message | Object | Yes | Data to be sent to the worker thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| transfer | ArrayBuffer[] | Yes | **ArrayBuffer** instance holding an array of objects for which the ownership is transferred to the worker thread. After the transfer, the objects are available only in the worker thread. The array cannot be null.|
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
Used by the host thread to send a message to the worker thread by transferring object ownership or copying data.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorker.postMessage<sup>9+</sup>](#postmessage9-1) instead.
...
...
@@ -1296,8 +1296,8 @@ Sends a message to the worker thread. The data type of the message must be seque
| message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The default value is **undefined**.|
| message | Object | Yes | Data to be sent to the worker thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| options | [PostMessageOptions](#postmessageoptions) | No | If this parameter is specified, it functions the same as **ArrayBuffer[]**. Specifically, the ownership of the objects in the array is transferred to the worker thread and becomes unavailable in the host thread. The objects are available only in the worker thread.<br>If this parameter is not specified, the default value **undefined** is used, and information is transferred to the worker thread by copying data.|
**Example**
...
...
@@ -1696,7 +1696,7 @@ Implements communication between the worker thread and the host thread. The **po
| messageObject | Object | Yes | Message to be sent to the host thread. |
| messageObject | Object | Yes | Data to be sent to the host thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| transfer| Transferable[] | Yes | Currently, this parameter is not supported. |
| message | Object | Yes | Data to be sent to the host thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| transfer | ArrayBuffer[] | Yes | **ArrayBuffer** instance holding an array of objects for which the ownership is transferred to the host thread. After the transfer, the objects are available only in the host thread. The array cannot be null.|
Sends a message to the host thread from the worker thread.
Used by the worker thread to send a message to the host thread by transferring object ownership or copying data.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorkerGlobalScope<sup>9+</sup>.postMessage<sup>9+</sup>](#postmessage9-3).
...
...
@@ -1767,8 +1767,8 @@ Sends a message to the host thread from the worker thread.
| message | Object | Yes | Message to be sent to the host thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The default value is **undefined**.|
| message | Object | Yes | Data to be sent to the host thread. The data object must be sequenceable. For details about the supported parameter types, see [Sequenceable Data Types](#sequenceable-data-types).|
| options | [PostMessageOptions](#postmessageoptions) | No | If this parameter is specified, it functions the same as **ArrayBuffer[]**. Specifically, the ownership of the objects in the array is transferred to the host thread and becomes unavailable in the worker thread. The objects are available only in the host thread.<br>If this parameter is not specified, the default value **undefined** is used, and information is transferred to the host thread by copying data.|
Specifies the object whose ownership needs to be transferred during data transfer. The object must be **ArrayBuffer**.
Defines the object for which the ownership is to be transferred during data transfer. The object must be an **ArrayBuffer** instance. After the ownership is transferred, the object becomes unavailable in the sender and can be used only in the receiver.
The worker thread is implemented based on the actor model. In the worker interaction process, the JS main thread can create multiple worker threads, each of which are isolated and transfer data through sequentialization. They complete computing tasks and return the result to the main thread.
The worker thread is implemented based on the actor model. In the worker interaction process, the JS main thread can create multiple worker threads, each of which are isolated and transfer data through serialization. They complete computing tasks and return the result to the main thread.
Each actor concurrently processes tasks of the main thread. For each actor, there is a message queue and a single-thread execution module. The message queue receives requests from the main thread and other actors; the single-thread execution module serially processes requests, sends requests to other actors, and creates new actors. These isolated actors use the asynchronous mode and can run concurrently.
### Precautions
- Currently, a maximum of seven workers can co-exist.
- Currently, a maximum of eight workers can co-exist.
- In API version 8 and earlier versions, when the number of **Worker** instances exceeds the upper limit, the error "Too many workers, the number of workers exceeds the maximum." is thrown.
- Since API version 9, when the number of **Worker** instances exceeds the upper limit, the business error "Worker initialization failure, the number of workers exceeds the maximum" is thrown.
- Since API version 9, when the number of **Worker** instances exceeds the upper limit, the business error "Worker initialization failure, the number of workers exceeds the maximum." is thrown.
- To proactively destroy a worker thread, you can call **terminate()** or **parentPort.close()** of the newly created **Worker** instance.
- Since API version 9, if a **Worker** instance in a non-running state (such as destroyed or being destroyed) calls an API, a business error is thrown.
- Creating and terminating worker threads consume performance. Therefore, you are advised to manage available workers and reuse them.
- Do not use both **new worker.Worker** and **new worker.ThreadWorker** to create a **Worker** project. Otherwise, **Worker** functions abnormally. Since API version 9, you are advised to use [new worker.ThreadWorker](#constructor9). In API version 8 and earlier versions, you are advised to use [new worker.Worker](#constructordeprecated).
- When creating a **Worker** project, do not import any UI construction method (such as .ets file) to the worker thread file (for example, **worker.ts** used in this document). Otherwise, the worker module becomes invalid. To check whether any UI construction method has been imported, decompress the generated HAP file, find **worker.js** in the directory where the worker thread is created, and search for the keyword **View** globally. If the keyword exists, a UI construction method has been packaged in **worker.js**. If this is your case, change the directory level of **src** in the statement **import "xxx" from src** in the worker thread file.
- A maximum of 16 MB data can be transferred during inter-thread communication.
| inFile | string | Yes | Path of the file to decompress. The file name extension must be .zip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. The path must exist in the system. Otherwise, the decompression fails. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. The path must exist in the system. Otherwise, the decompression fails. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md). If a file or folder with the same name already exists in the path, they will be overwritten.|
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
...
...
@@ -259,9 +259,7 @@ import zlib from '@ohos.zlib';
| inFile | string | Yes | Path of the file to decompress. The file name extension must be .zip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. The path must exist in the system. Otherwise, the decompression fails. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. The path must exist in the system. Otherwise, the decompression fails. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model](js-apis-inner-application-context.md). If a file or folder with the same name already exists in the path, they will be overwritten.|
@@ -246,7 +246,7 @@ Check the functions required by the tasks executed by the task pool and add the
**Error Message**
The task is not exist when cancel it.
The task does not exist when it is canceled.
**Description**
...
...
@@ -258,13 +258,13 @@ The task to cancel does not exist in the task pool.
**Solution**
Before canceling a task, ensure that the task is placed into the task pool by calling **taskpool.execute**.
Before canceling a task, ensure that the task has been placed in the task pool by calling **taskpool.execute** and is not finishing. If you are not sure, capture exceptions.
## 10200016 Failed to Cancel a Task Being Executed
**Error Message**
The task is running when cancel it.
The task is executing when it is canceled.
**Description**
...
...
@@ -276,7 +276,7 @@ The task to cancel is being executed.
**Solution**
Before canceling a task, ensure that the task finishes execution.
Before canceling a task, ensure that the task has been placed in the task pool by calling **taskpool.execute** and has not started execution. If you are not sure, capture exceptions.
## 10200017 Failed to Delete an Element That Does Not Exist
...
...
@@ -295,3 +295,21 @@ The element to delete does not exist in the container.
**Solution**
Before deleting an element, ensure that the element exists in this container.
## 10200018 Failed to Cancel a Task Group That Does Not Exist
**Error Message**
The task group does not exist when it is canceled.
**Description**
This error code is reported when you attempt to cancel a task group that does not exist.
**Possible Causes**
The task group to cancel does not exist in the task pool.
**Solution**
Before canceling a task group, ensure that the task group is placed in the task pool by calling **taskpool.execute** and is not finishing. If you are not sure, capture exceptions.