提交 5fdc53cc 编写于 作者: W wangzhaoyong

add errorcode

Signed-off-by: Nwangzhaoyong <wangzhaoyong@huawei.com>
Change-Id: Ibbf8c6d08103b39a0b3a547b327bc4ca32d5e8a5
上级 36e9f30d
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
- [MissionListener](js-apis-inner-application-missionListener.md) - [MissionListener](js-apis-inner-application-missionListener.md)
- [MissionParameter](js-apis-inner-application-missionParameter.md) - [MissionParameter](js-apis-inner-application-missionParameter.md)
- [MissionSnapshot](js-apis-inner-application-missionSnapshot.md) - [MissionSnapshot](js-apis-inner-application-missionSnapshot.md)
- [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) - [PermissionRequestResult](js-apis-permissionrequestresult.md)
- [ProcessData](js-apis-inner-application-processData.md) - [ProcessData](js-apis-inner-application-processData.md)
- [ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md) - [ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)
- [ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md) - [ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)
...@@ -343,6 +343,7 @@ ...@@ -343,6 +343,7 @@
- [@ohos.buffer (Buffer)](js-apis-buffer.md) - [@ohos.buffer (Buffer)](js-apis-buffer.md)
- [@ohos.convertxml (xml转换JavaScript)](js-apis-convertxml.md) - [@ohos.convertxml (xml转换JavaScript)](js-apis-convertxml.md)
- [@ohos.process (获取进程相关的信息)](js-apis-process.md) - [@ohos.process (获取进程相关的信息)](js-apis-process.md)
- [@ohos.taskpool (启动任务池)](js-apis-taskpool.md)
- [@ohos.uri (URI字符串解析)](js-apis-uri.md) - [@ohos.uri (URI字符串解析)](js-apis-uri.md)
- [@ohos.url (URL字符串解析)](js-apis-url.md) - [@ohos.url (URL字符串解析)](js-apis-url.md)
- [@ohos.util (util工具函数)](js-apis-util.md) - [@ohos.util (util工具函数)](js-apis-util.md)
......
...@@ -2,102 +2,108 @@ ...@@ -2,102 +2,108 @@
taskpool作用是为应用程序提供一个多线程的运行环境,可以降低整体资源的消耗、提高系统的整体性能,且用户无需关心线程实例的生命周期。 taskpool作用是为应用程序提供一个多线程的运行环境,可以降低整体资源的消耗、提高系统的整体性能,且用户无需关心线程实例的生命周期。
> **说明:**<br/>
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```js ```js
import taskpool from '@ohos.taskpool'; import taskpool from '@ohos.taskpool';
``` ```
## 属性 ## Priority
**系统能力:** SystemCapability.Utils.Lang 表示所创建任务(Task)的优先级。(暂未支持)
| 名称 | 可读 | 可写 | 说明 | **系统能力:** SystemCapability.Utils.Lang
| -------- | ---- | ---- | ---------------------------------------------------------- |
| taskpool | 是 | 是 | taskpool对象用于管理Task(任务),可以创建、执行和取消Task |
## Task | 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| HIGH | 0 | 任务为高优先级。 |
| MEDIUM | 1 | 任务为中优先级。 |
| LOW | 2 | 任务为低优先级。 |
使用以下方法前,需要先构造Task。 ## Task
| 名称 | 类型 | 可读 | 可写 | 说明 | 表示任务。使用以下方法前,需要先构造Task。
| ---- | ---- | ---- | ---- | -------------------------------------------------------- |
| Task | Task | 是 | 是 | 待执行的任务。需要创建Task再放入taskpool(任务池)中执行 |
### constructor ### constructor
constructor(func: Function, ...args: unknown[]) constructor(func: Function, ...args: unknown[])
Task构造函数 Task的构造函数。
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | --------- | ---- | ---------------------------------------------- | | ------ | --------- | ---- | ------------------------ |
| func | Function | 是 | Task执行的逻辑需要传入Function | | func | Function | 是 | 任务执行需要传入函数。 |
| args | unknown[] | 否 | Task执行逻辑的Function如果需要入参,则需要传递 | | args | unknown[] | 否 | 任务执行传入函数的参数。 |
**返回值:**
| 类型 | 说明 |
| ---- | --------------------------------------------------- |
| Task | 执行Task构造函数生成的Task对象,失败则返回undefined |
**错误码:** **错误码:**
| 错误码 | 错误说明 | 以下错误码的详细介绍请参见[语言基础类库错误码](../errorcodes/errorcode-utils.md)
| 错误码ID | 错误信息 |
| -------- | --------------------------------------- | | -------- | --------------------------------------- |
| 401 | the input parameters are invalid. | | 10200014 | The function is not mark as concurrent. |
| 10200014 | the function is not mark as concurrent. |
**示例:** **示例:**
```js ```js
import taskpool from '@ohos.taskpool';
function func(args) { function func(args) {
"use concurrent" "use concurrent"
console.log("func: " + args); console.log("func: " + args);
return args; return args;
} }
var task = new taskpool.Task(func, "this is first Task"); let task = new taskpool.Task(func, "this is my first Task");
``` ```
### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 类型 | 可读 | 可写 | 说明 |
| --------- | --------- | ---- | ---- | ---------------------------- |
| function | Function | 是 | 是 | 创建任务时需要传入的函数。 |
| arguments | unknown[] | 是 | 是 | 创建任务传入函数所需的参数。 |
## taskpool.execute
## execute execute(func: Function, ...args: unknown[]): Promise\<unknown>
execute(func: Function, ...args: unknown[]): Promise<unknown> 任务池执行任务,需要传入待执行的函数和函数所需的参数,此执行模式不可取消任务。
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | --------- | ---- | ------------------------------------------ | | ------ | --------- | ---- | ---------------------------- |
| func | Function | 是 | 执行的逻辑需要传入Function | | func | Function | 是 | 执行的逻辑需要传入函数。 |
| args | unknown[] | 否 | 执行逻辑的Function如果需要入参,则需要传递 | | args | unknown[] | 否 | 执行逻辑的函数所需要的参数。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | ------------------------------ | | ----------------- | ------------------------------------ |
| Promise<unknown> | execute是异步方法,返回Promise | | Promise\<unknown> | execute是异步方法,返回Promise对象。 |
**错误码:** **错误码:**
| 错误码 | 错误说明 | 以下错误码的详细介绍请参见[语言基础类库错误码](../errorcodes/errorcode-utils.md)
| -------- | --------------------------------------- |
| 401 | the input parameters are invalid. | | 错误码ID | 错误信息 |
| 10200014 | the function is not mark as concurrent. | | -------- | ----------------------------------------- |
| 10200003 | Worker initialization failure. |
| 10200006 | Serializing an uncaught exception failed. |
| 10200014 | The function is not mark as concurrent. |
**示例:** **示例:**
```js ```js
import taskpool from '@ohos.taskpool';
function func(args) { function func(args) {
"use concurrent" "use concurrent"
console.log("func: " + args); console.log("func: " + args);
...@@ -107,84 +113,81 @@ function func(args) { ...@@ -107,84 +113,81 @@ function func(args) {
let value = taskpool.execute(func, 100); let value = taskpool.execute(func, 100);
``` ```
## taskpool.execute
execute(task: Task, priority?: Priority): Promise\<unknown>
execute(task: Task, priority?: Priority): Promise<unknown>; 任务池执行任务,需要传入已创建的任务,此执行模式可取消任务。
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | ---- | -------------------------------- | | -------- | --------------------- | ---- | ------------------------------------ |
| task | Task | 是 | 需要在taskpool中执行的任务 | | task | [Task](#task) | 是 | 需要在任务池中执行的任务。 |
| priority | Priority | 否 | 等待执行的Task的优先级,暂未实现 | | priority | [Priority](#priority) | 否 | 等待执行的任务的优先级(暂未支持)。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | ------------------------------ | | ---------------- | ------------------------------ |
| Promise<unknown> | execute是异步方法,返回Promise | | Promise\<unknown> | execute是异步方法,返回Promise对象。 |
**错误码:** **错误码:**
| 错误码 | 错误说明 | 以下错误码的详细介绍请参见[语言基础类库错误码](../errorcodes/errorcode-utils.md)
| -------- | --------------------------------------- |
| 401 | the input parameters are invalid. | | 错误码ID | 错误信息 |
| 10200014 | the function is not mark as concurrent. | | -------- | ----------------------------------------- |
| 10200003 | Worker initialization failure. |
| 10200006 | Serializing an uncaught exception failed. |
| 10200014 | The function is not mark as concurrent. |
**示例:** **示例:**
```js ```js
import taskpool from '@ohos.taskpool';
function func(args) { function func(args) {
"use concurrent" "use concurrent"
console.log("func: " + args); console.log("func: " + args);
return args; return args;
} }
var task = new taskpool.Task(func, "this is first Task"); let task = new taskpool.Task(func, "this is my first Task");
let value = taskpool.execute(task); let value = taskpool.execute(task);
``` ```
## taskpool.cancel
## cancel
cancel(task: Task): void cancel(task: Task): void
取消任务池中的任务。
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | ------------------------------ | | ------ | ------------- | ---- | -------------------- |
| task | Task | 是 | 需要在taskpool中取消执行的任务 | | task | [Task](#task) | 是 | 需要取消执行的任务。 |
**返回值:**
| 类型 | 说明 |
| ---- | -------- |
| void | 无返回值 |
**错误码:** **错误码:**
| 错误码 | 错误信息 | 以下错误码的详细介绍请参见[语言基础类库错误码](../errorcodes/errorcode-utils.md)
| -------- | --------------------- |
| 10200015 | the task is not exist | | 错误码ID | 错误信息 |
| 10200016 | the task is running | | -------- | ------------------------- |
| 10200015 | If the task is not exist. |
| 10200016 | If the task is running. |
**示例:** **示例:**
```js ```js
import taskpool from '@ohos.taskpool';
function func(args) { function func(args) {
"use concurrent" "use concurrent"
console.log("func: " + args); console.log("func: " + args);
return args; return args;
} }
var task = new taskpool.Task(func, "this is first Task"); let task = new taskpool.Task(func, "this is first Task");
let value = taskpool.execute(task); let value = taskpool.execute(task);
taskpool.cancel(task); taskpool.cancel(task);
``` ```
\ No newline at end of file
...@@ -219,3 +219,57 @@ Buffer的属性${propertyName}只读,不能进行设置。 ...@@ -219,3 +219,57 @@ Buffer的属性${propertyName}只读,不能进行设置。
**处理步骤** **处理步骤**
不要对Buffer只读属性进行相关设置。 不要对Buffer只读属性进行相关设置。
## 10200014 非Concurrent函数错误
**错误信息**
The function is not mark as concurrent.
**错误描述**
Function未被标记为concurrent。
**可能原因**
任务池执行的任务所需的函数未添加@Concurrent。
**处理步骤**
检查任务池执行的任务所需的函数,并补上@Concurrent装饰器。
## 10200015 取消不存在的任务错误
**错误信息**
The task is not exist when cancel it.
**错误描述**
取消一个不存在的任务。
**可能原因**
取消任务时,该任务并不存在于任务池中。
**处理步骤**
取消任务前,确保任务已被taskpool.execute调用进入任务池。
## 10200016 取消已执行的任务错误
**错误信息**
The task is running when cancel it.
**错误描述**
取消已经执行的任务。
**可能原因**
取消任务时,该任务已经处于执行状态。
**处理步骤**
取消任务前,确保任务已被执行完毕。
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册