未验证 提交 b11a47a0 编写于 作者: O openharmony_ci 提交者: Gitee

!14059 翻译完成:13745 add taskpool doc monthly1018

Merge pull request !14059 from wusongqing/TR13745
# @ohos.application.AccessibilityExtensionAbility
# @ohos.application.AccessibilityExtensionAbility (AccessibilityExtensionAbility)
The **AccessibilityExtensionAbility** module provides accessibility extension capabilities based on the ExtensionAbility framework.
......
......@@ -2771,6 +2771,7 @@ try {
### bundleManager.getApplicationInfoSync
getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);
getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);
Synchronously obtains the application information based on the given bundle name, application flags, and user ID.
......@@ -2786,7 +2787,7 @@ Synchronously obtains the application information based on the given bundle name
| ----------- | ------ | ---- | ----------------------------------------------------------|
| bundleName | string | Yes | Bundle name. |
| applicationFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| userId | number | No | User ID. |
| userId | number | Yes | User ID. |
**Return value**
......@@ -2838,6 +2839,7 @@ try {
### bundleManager.getBundleInfoSync
getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId: number): [BundleInfo](js-apis-bundleManager-bundleInfo.md);
getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md);
Synchronously obtains the bundle information based on the given bundle name, bundle flags, and user ID.
......
# @ohos.util.Deque (Linear Container Deque)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Double-ended queue (deque) is a sequence container implemented based on the queue data structure that follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). It allows insertion and removal of elements at both the ends. **Deque** can dynamically adjust the capacity based on project requirements. It doubles the capacity each time. **Deque** differs from **[Queue](js-apis-queue.md)** and **[Vector](js-apis-vector.md)** mainly in the following aspects:
......
# File Interaction
# @ohos.document (File Interaction)
> **NOTE**<br/>
> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
# File Management
# @ohos.fileio (File Management)
The **fileio** module provides APIs for file storage and management, including basic file management, directory management, file information statistics, and stream read and write.
......@@ -40,7 +40,7 @@ FA Model
let pathDir = data;
})
```
For details about how to obtain the context of the FA model, see [FA Model](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-Context.md#context).
## fileio.stat
......
# @ohos.bundle.launcherBundleManager
# @ohos.bundle.launcherBundleManager (launcherBundleManager)
The **bundle.launcherBundleManager** module providers APIs for the **Home Screen** application to obtain the launcher ability information and shortcut information.
......
# @ohos.reminderAgent (reminderAgent)
# @ohos.reminderAgent (Reminder Agent)
The **reminderAgent** module provides APIs for publishing scheduled reminders through the reminder agent.
......
# @ohos.reminderAgentManager (reminderAgentManager)
# @ohos.reminderAgentManager (Reminder Agent Management)
The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent.
......
# @ohos.resourceschedule.workScheduler (workScheduler)
# @ohos.resourceschedule.workScheduler (Work Scheduler)
The **workScheduler** module provides the APIs for registering, canceling, and querying Work Scheduler tasks, which do not have real-time constraints.
......
# @ohos.screenshot
# @ohos.screenshot (Screenshot)
The **Screenshot** module provides APIs for you to set information such as the region to capture and the size of the screen region when capturing a screen.
......
# statfs
# @ohos.statfs (statfs)
The statfs module provides APIs for obtaining file system information, including the total number of bytes and the number of idle bytes of the file system.
......
# Bluetooth
# @system.bluetooth (Bluetooth)
> **NOTE**<br/>
......
# Application Configuration
# @system.configuration (Application Configuration)
> **NOTE**<br>
> - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.i18n`](js-apis-i18n.md) and [`@ohos.intl`](js-apis-intl.md) instead.
......
# Data Request
# @system.fetch (Data Request)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> **NOTE**
>
> - The APIs of this module are no longer maintained since API version 6. You are advised to use [`@ohos.net.http`](js-apis-http.md) instead.
>
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
# File Storage
# @system.file (File Storage)
> **NOTE**<br>
> - The APIs of this module are no longer maintained since API version 6. You are advised to use [`@ohos.fileio`](js-apis-fileio.md).
......
# Geographic Location
# @system.geolocation (Geographic Location)
> **NOTE**
>
> - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.geolocation`](js-apis-geolocation.md).
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
# @ohos.taskpool (Using the Task Pool)
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.)
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.)
The **TaskPool** APIs return error codes in numeric format. For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
> **NOTE**<br>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import taskpool from '@ohos.taskpool';
```
## Priority
Enumerates the priorities available for created tasks. (This enum is not supported yet.)
**System capability**: SystemCapability.Utils.Lang
| Name| Value| Description|
| -------- | -------- | -------- |
| HIGH | 0 | The task has a high priority.|
| MEDIUM | 1 | The task has a medium priority.|
| LOW | 2 | The task has a low priority.|
## Task
Implements a task. Before using any of the following APIs, you must create a **Task** instance.
### constructor
constructor(func: Function, ...args: unknown[])
A constructor used to create a **Task** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | --------- | ---- | -------------------------------------------------------------------- |
| 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).|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | --------------------------------------- |
| 10200014 | The function is not mark as concurrent. |
**Example**
```js
function func(args) {
"use concurrent"
console.log("func: " + args);
return args;
}
let task = new taskpool.Task(func, "this is my first Task");
```
### Attributes
**System capability**: SystemCapability.Utils.Lang
| Name | Type | Readable| Writable| Description |
| --------- | --------- | ---- | ---- | ------------------------------------------------------------------------- |
| 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).|
## taskpool.execute
execute(func: Function, ...args: unknown[]): Promise\<unknown>
Executes a task in the task pool. You must pass in a function and arguments to execute the task, and the task executed in this mode cannot be canceled.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | --------- | ---- | ---------------------------------------------------------------------- |
| func | Function | Yes | Function used to execute the task. 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).|
**Return value**
| Type | Description |
| ----------------- | ------------------------------------ |
| Promise\<unknown> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 10200003 | Worker initialization failure. |
| 10200006 | Serializing an uncaught exception failed. |
| 10200014 | The function is not mark as concurrent. |
**Example**
```js
function func(args) {
"use concurrent"
console.log("func: " + args);
return args;
}
let value = taskpool.execute(func, 100);
```
## taskpool.execute
execute(task: Task, priority?: Priority): Promise\<unknown>
Executes a task in the task pool. You must pass in a created task, and the task executed in this mode can be canceled.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------ |
| task | [Task](#task) | Yes | Task to be executed. |
| priority | [Priority](#priority) | No | Priority of the task (not supported yet).|
**Return value**
| Type | Description |
| ---------------- | ------------------------------ |
| Promise\<unknown> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 10200003 | Worker initialization failure. |
| 10200006 | Serializing an uncaught exception failed. |
| 10200014 | The function is not mark as concurrent. |
**Example**
```js
function func(args) {
"use concurrent"
console.log("func: " + args);
return args;
}
let task = new taskpool.Task(func, "this is my first Task");
let value = taskpool.execute(task);
```
## taskpool.cancel
cancel(task: Task): void
Cancels a task in the task pool.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------- | ---- | -------------------- |
| task | [Task](#task) | Yes | Task to cancel.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------- |
| 10200015 | If the task is not exist. |
| 10200016 | If the task is running. |
**Example**
```js
function func(args) {
"use concurrent"
console.log("func: " + args);
return args;
}
let task = new taskpool.Task(func, "this is first Task");
let value = taskpool.execute(task);
taskpool.cancel(task);
```
## Additional Information
### Sequenceable Data Types
The following sequenceable data types are supported: All Primitive Type (excluding symbol), Date, String, RegExp, Array, Map, Set, Object, ArrayBuffer, and TypedArray.
### Precautions
A task in the task pool can reference only variables passed in by input parameters or imported variables. It does not support closure variables.
```js
// 1. Reference a variable passed in by the input parameter.
function func(args) {
"use concurrent"
console.log("func: " + args);
return args;
}
let task = new taskpool.Task(func, "create task, then execute");
let val1 = taskpool.execute(task);
let val2 = taskpool.execute(func, "execute task by func");
```
```js
// 2. Reference an imported variable.
// b.ts
export var c = 2000;
// a.ts
import { c } from './b'
function test(a) {
"use concurrent"
console.log(a);
console.log(c);
return a;
}
let task = new taskpool.Task(test, "create task, then execute");
let val1 = taskpool.execute(task);
let val2 = taskpool.execute(test, "execute task by func");
```
# @ohos.wantAgent
# @ohos.wantAgent (wantAgent)
The **WantAgent** module provides APIs for creating and comparing **WantAgent** objects, and obtaining the user ID and bundle name of a **WantAgent** object.
......
......@@ -52,7 +52,7 @@ You can create a subwindow, such as a dialog box, and set its properties.
let windowClass = null;
// Method 1: Create a subwindow.
let config = {name: "subWindow", windowType: window.WindowType.TYPE_APP, ctx: this.context};
let config = {name: "subWindow", windowType: window.WindowType.TYPE_APP};
window.createWindow(config, (err, data) => {
if (err.code) {
console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
......
......@@ -390,4 +390,3 @@ A floating window is created based on an existing task. It is always displayed i
};
```
<!--no_check-->
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册