未验证 提交 1ebbbd17 编写于 作者: 朱天怡 提交者: Gitee

修改

Signed-off-by: N朱天怡 <zhutianyi2@huawei.com>
上级 3aa79ec5
# 延迟任务调度
本模块提供延迟任务注册、取消、查询的能力。
开发者在开发应用时,通过调用延迟任务注册接口,注册对实时性要求不高的延迟任务,该任务默认由系统安排,在系统空闲时根据性能、功耗、热等情况进行调度执行。
> **说明:**
>
> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口仅可在Stage模型下使用。
> - 延迟任务调度约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)。
> - 延迟任务调度错误码见[workScheduler错误码](../errorcodes/errorcode-workScheduler.md)。
## 导入模块
```js
import workScheduler from '@ohos.resourceschedule.workScheduler';
```
## workScheduler.startWork<sup>9+</sup>
startWork(work: WorkInfo): void
通知WorkSchedulerService将工作添加到执行队列。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| ---- | --------------------- | ---- | -------------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要添加到执行队列的工作。 |
**示例**:
```js
let workInfo = {
workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false,
isPersisted: true,
bundleName: "com.example.myapplication",
abilityName: "MyExtension",
parameters: {
mykey0: 1,
mykey1: "string value",
mykey2: true,
mykey3: 1.5
}
}
try{
workScheduler.startWork(workInfo);
console.info('workschedulerLog startWork success');
} catch (error) {
console.error(`workschedulerLog startwork failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.stopWork<sup>9+</sup>
stopWork(work: WorkInfo, needCancel?: boolean): void
通知WorkSchedulerService停止指定工作。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | --------------------- | ---- | ---------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 |
| needCancel | boolean | 是 | 是否需要取消的工作。 |
**示例**:
```js
let workInfo = {
workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false,
isPersisted: true,
bundleName: "com.example.myapplication",
abilityName: "MyExtension",
parameters: {
mykey0: 1,
mykey1: "string value",
mykey2: true,
mykey3: 1.5
}
}
try{
workScheduler.stopWork(workInfo, false);
console.info('workschedulerLog stopWork success');
} catch (error) {
console.error(`workschedulerLog stopWork failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.getWorkStatus:callback<sup>9+</sup>
getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
获取工作的最新状态,使用Callback形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------- | ---- | ---------------------------------------- |
| workId | number | 是 | work的id。 |
| callback | AsyncCallback\<[WorkInfo](#workinfo)> | 是 | 指定的callback回调方法。如果指定的工作Id有效,则返回从WorkSchedulerService获取的有效工作状态;否则返回null。 |
**示例**:
```js
try{
workScheduler.getWorkStatus(50, (error, res) => {
if (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
} else {
for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
}
});
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.getWorkStatus:promise<sup>9+</sup>
getWorkStatus(workId: number): Promise\<WorkInfo>
获取工作的最新状态,使用Promise形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| workId | number | 是 | work的id。 |
**返回值**:
| 类型 | 说明 |
| ------------------------------- | ---------------------------------------- |
| Promise\<[WorkInfo](#workinfo)> | 指定的Promise回调方法。如果指定的工作ID有效,则返回从WorkSchedulerService获取的有效工作状态;否则返回null。 |
**示例**:
```js
try{
workScheduler.getWorkStatus(50).then((res) => {
for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
}).catch((error) => {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
})
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.obtainAllWorks:callback<sup>9+</sup>
obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
获取与当前应用程序关联的所有工作,使用Callback形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------- |
| callback | AsyncCallback\<void> | 是 | 指定的callback回调方法。返回与应用程序关联的所有工作。 |
**返回值**:
| 类型 | 说明 |
| ----------------------------- | --------------- |
| Array\<[WorkInfo](#workinfo)> | 返回与应用程序关联的所有工作。 |
**示例**:
```js
try{
workScheduler.obtainAllWorks((error, res) =>{
if (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
} else {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}
});
} catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.obtainAllWorks:promise<sup>9+</sup>
obtainAllWorks(): Promise<Array\<WorkInfo>>
获取与当前应用程序关联的所有工作,使用Promise形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**返回值**:
| 类型 | 说明 |
| -------------------------------------- | ------------------------------ |
| Promise<Array\<[WorkInfo](#workinfo)>> | 指定的Promise回调方法。返回与应用程序关联的所有工作。 |
**示例**:
```js
try{
workScheduler.obtainAllWorks().then((res) => {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}).catch((error) => {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
})
} catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.stopAndClearWorks
stopAndClearWorks(): void
停止和取消与当前应用程序关联的所有工作。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**示例**:
```js
try{
workScheduler.stopAndClearWorks();
console.info(`workschedulerLog stopAndClearWorks success`);
} catch (error) {
console.error(`workschedulerLog stopAndClearWorks failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.isLastWorkTimeOut:callback<sup>9+</sup>
isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
检查指定工作的最后一次执行是否为超时操作,使用Callback形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------------------- |
| workId | number | 是 | work的id。 |
| callback | AsyncCallback\<void> | 是 | 指定的callback回调方法。如果指定工作的最后一次执行是超时操作,则返回true;否则返回false。 |
**返回值**:
| 类型 | 说明 |
| ------- | ---------------------------------------- |
| boolean | 指定的callback回调方法。如果指定工作的最后一次执行是超时操作,则返回true;否则返回false。 |
**示例**:
```js
try{
workScheduler.isLastWorkTimeOut(500, (error, res) =>{
if (error) {
onsole.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
} else {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
}
});
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.isLastWorkTimeOut:promise<sup>9+</sup>
isLastWorkTimeOut(workId: number): Promise\<boolean>
检查指定工作的最后一次执行是否为超时操作,使用Promise形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**:
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| workId | number | 是 | work的id。 |
**返回值**:
| 类型 | 说明 |
| ----------------- | ---------------------------------------- |
| Promise\<boolean> | 指定的Promise回调方法。如果指定工作的最后一次执行是超时操作,则返回true;否则返回false。 |
**示例**:
```js
try{
workScheduler.isLastWorkTimeOut(500)
.then(res => {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
})
.catch(error => {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
});
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
```
## WorkInfo
提供工作的具体信息。WorkInfo设置参数约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | --------------------------------- | ---- | ---------------- |
| workId | number | 是 | 当前工作的ID |
| bundleName | string | 是 | 延迟任务包名 |
| abilityName | string | 是 | 延迟任务回调通知的组件名(必填) |
| networkType | [NetworkType](#networktype) | 否 | 网络类型 |
| isCharging | boolean | 否 | 是否充电 |
| chargerType | [ChargingType](#chargingtype) | 否 | 充电类型 |
| batteryLevel | number | 否 | 电量 |
| batteryStatus | [BatteryStatus](#batterystatus) | 否 | 电池状态 |
| storageRequest | [StorageRequest](#storagerequest) | 否 | 存储状态 |
| isRepeat | boolean | 否 | 是否循环任务 |
| repeatCycleTime | number | 否 | 循环间隔 |
| repeatCount | number | 否 | 循环次数 |
| isPersisted | boolean | 否 | 是否持久化保存工作 |
| isDeepIdle | boolean | 否 | 是否要求设备进入空闲状态 |
| idleWaitTime | number | 否 | 空闲等待时间 |
| parameters | {[key: string]: any} | 否 | 携带参数信息 |
## NetworkType
触发工作的网络类型。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 默认值 | 说明 |
| ---------------------- | ---- | ----------------------- |
| NETWORK_TYPE_ANY | 0 | 表示这个触发条件是任何类型的网络连接。 |
| NETWORK_TYPE_MOBILE | 1 | 表示这个触发条件是Mobile网络连接。 |
| NETWORK_TYPE_WIFI | 2 | 表示这个触发条件是Wifi类型的网络连接。 |
| NETWORK_TYPE_BLUETOOTH | 3 | 表示这个触发条件是Bluetooth网络连接。 |
| NETWORK_TYPE_WIFI_P2P | 4 | 表示这个触发条件是Wifi P2P网络连接。 |
| NETWORK_TYPE_ETHERNET | 5 | 表示这个触发条件是有线网络连接。 |
## ChargingType
触发工作的充电类型。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 默认值 | 说明 |
| ------------------------- | ---- | -------------------- |
| CHARGING_PLUGGED_ANY | 0 | 表示这个触发条件是任何类型的充电器连接。 |
| CHARGING_PLUGGED_AC | 1 | 表示这个触发条件是直流充电器连接。 |
| CHARGING_PLUGGED_USB | 2 | 表示这个触发条件是USB充连接。 |
| CHARGING_PLUGGED_WIRELESS | 3 | 表示这个触发条件是无线充电器连接。 |
## BatteryStatus
触发工作的电池状态。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 默认值 | 说明 |
| -------------------------- | ---- | -------------------------- |
| BATTERY_STATUS_LOW | 0 | 表示这个触发条件是低电告警。 |
| BATTERY_STATUS_OKAY | 1 | 表示这个触发条件是从低电恢复到正常电量。 |
| BATTERY_STATUS_LOW_OR_OKAY | 2 | 表示这个触发条件是从低电恢复到正常电量或者低电告警。 |
## StorageRequest
触发工作的存储状态。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 默认值 | 说明 |
| ------------------------- | ---- | ------------------------------ |
| STORAGE_LEVEL_LOW | 0 | 表示这个触发条件是存储空间不足。 |
| STORAGE_LEVEL_OKAY | 1 | 表示这个触发条件是从存储空间不足恢复到正常。 |
| STORAGE_LEVEL_LOW_OR_OKAY | 2 | 表示这个触发条件是从存储空间不足恢复到正常或者存储空间不足。 |
\ No newline at end of file
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口仅可在Stage模型下使用。 > - 本模块接口仅可在Stage模型下使用。
> - 延迟任务调度约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)。 > - 延迟任务调度约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)。
> - 延迟任务调度错误码见[workScheduler错误码](../errorcodes/errorcode-workScheduler.md)。
## 导入模块 ## 导入模块
...@@ -19,10 +18,14 @@ import workScheduler from '@ohos.workScheduler'; ...@@ -19,10 +18,14 @@ import workScheduler from '@ohos.workScheduler';
``` ```
## workScheduler.startWork ## workScheduler.startWork
startWork(work: WorkInfo): void startWork(work: WorkInfo): boolean
通知WorkSchedulerService将工作添加到执行队列。 通知WorkSchedulerService将工作添加到执行队列。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.startWork](../js-apis-resourceschedule-workScheduler.md/#workschedulerstartwork9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数** **参数**
...@@ -31,6 +34,12 @@ startWork(work: WorkInfo): void ...@@ -31,6 +34,12 @@ startWork(work: WorkInfo): void
| ---- | --------------------- | ---- | -------------- | | ---- | --------------------- | ---- | -------------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要添加到执行队列的工作。 | | work | [WorkInfo](#workinfo) | 是 | 指示要添加到执行队列的工作。 |
**返回值**
| 类型 | 说明 |
| ------- | -------------------------------- |
| boolean | 如果工作成功添加到执行队列,则返回true,否则返回false。 |
**示例** **示例**
```js ```js
...@@ -48,19 +57,19 @@ startWork(work: WorkInfo): void ...@@ -48,19 +57,19 @@ startWork(work: WorkInfo): void
mykey3: 1.5 mykey3: 1.5
} }
} }
try{ var res = workScheduler.startWork(workInfo);
workScheduler.startWork(workInfo); console.info(`workschedulerLog res: ${res}`);
console.info('workschedulerLog startWork success');
} catch (error) {
console.error(`workschedulerLog startwork failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.stopWork ## workScheduler.stopWork
stopWork(work: WorkInfo, needCancel?: boolean): void stopWork(work: WorkInfo, needCancel?: boolean): boolean
通知WorkSchedulerService停止指定工作。 通知WorkSchedulerService停止指定工作。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.stopWork](../js-apis-resourceschedule-workScheduler.md/#workschedulerstopwork9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数** **参数**
...@@ -70,6 +79,12 @@ stopWork(work: WorkInfo, needCancel?: boolean): void ...@@ -70,6 +79,12 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
| work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 | | work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 |
| needCancel | boolean | 是 | 是否需要取消的工作。 | | needCancel | boolean | 是 | 是否需要取消的工作。 |
**返回值**
| 类型 | 说明 |
| ------- | ----------------------- |
| boolean | 如果成功,则返回true,否则返回false。 |
**示例** **示例**
```js ```js
...@@ -87,12 +102,8 @@ stopWork(work: WorkInfo, needCancel?: boolean): void ...@@ -87,12 +102,8 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
mykey3: 1.5 mykey3: 1.5
} }
} }
try{ var res = workScheduler.stopWork(workInfo, false);
workScheduler.stopWork(workInfo, false); console.info(`workschedulerLog res: ${res}`);
console.info('workschedulerLog stopWork success');
} catch (error) {
console.error(`workschedulerLog stopWork failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
...@@ -100,6 +111,10 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void ...@@ -100,6 +111,10 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
获取工作的最新状态,使用Callback形式返回。 获取工作的最新状态,使用Callback形式返回。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.getWorkStatus](../js-apis-resourceschedule-workScheduler.md/#workschedulergetworkstatuscallback9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数** **参数**
...@@ -112,19 +127,15 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void ...@@ -112,19 +127,15 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
**示例** **示例**
```js ```js
try{ workScheduler.getWorkStatus(50, (err, res) => {
workScheduler.getWorkStatus(50, (error, res) => { if (err) {
if (error) { console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`);
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
} else { } else {
for (let item in res) { for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
} }
} }
}); });
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
...@@ -132,6 +143,10 @@ getWorkStatus(workId: number): Promise\<WorkInfo> ...@@ -132,6 +143,10 @@ getWorkStatus(workId: number): Promise\<WorkInfo>
获取工作的最新状态,使用Promise形式返回。 获取工作的最新状态,使用Promise形式返回。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.getWorkStatus](../js-apis-resourceschedule-workScheduler.md/#workschedulergetworkstatuspromise9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数** **参数**
...@@ -149,17 +164,13 @@ getWorkStatus(workId: number): Promise\<WorkInfo> ...@@ -149,17 +164,13 @@ getWorkStatus(workId: number): Promise\<WorkInfo>
**示例** **示例**
```js ```js
try{
workScheduler.getWorkStatus(50).then((res) => { workScheduler.getWorkStatus(50).then((res) => {
for (let item in res) { for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
} }
}).catch((error) => { }).catch((err) => {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`); console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`);
}) })
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
...@@ -167,6 +178,10 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo> ...@@ -167,6 +178,10 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
获取与当前应用程序关联的所有工作,使用Callback形式返回。 获取与当前应用程序关联的所有工作,使用Callback形式返回。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.obtainAllWorks](../js-apis-resourceschedule-workScheduler.md/#workschedulerobtainallworkscallback9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数** **参数**
...@@ -184,17 +199,13 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo> ...@@ -184,17 +199,13 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
**示例** **示例**
```js ```js
try{ workScheduler.obtainAllWorks((err, res) =>{
workScheduler.obtainAllWorks((error, res) =>{ if (err) {
if (error) { console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`);
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
} else { } else {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
} }
}); });
} catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
...@@ -202,6 +213,10 @@ obtainAllWorks(): Promise<Array\<WorkInfo>> ...@@ -202,6 +213,10 @@ obtainAllWorks(): Promise<Array\<WorkInfo>>
获取与当前应用程序关联的所有工作,使用Promise形式返回。 获取与当前应用程序关联的所有工作,使用Promise形式返回。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.obtainAllWorks](../js-apis-resourceschedule-workScheduler.md/#workschedulerobtainallworkspromise9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**返回值** **返回值**
...@@ -213,33 +228,29 @@ obtainAllWorks(): Promise<Array\<WorkInfo>> ...@@ -213,33 +228,29 @@ obtainAllWorks(): Promise<Array\<WorkInfo>>
**示例** **示例**
```js ```js
try{
workScheduler.obtainAllWorks().then((res) => { workScheduler.obtainAllWorks().then((res) => {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}).catch((error) => { }).catch((err) => {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`); console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`);
}) })
} catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.stopAndClearWorks ## workScheduler.stopAndClearWorks
stopAndClearWorks(): void stopAndClearWorks(): boolean
停止和取消与当前应用程序关联的所有工作。 停止和取消与当前应用程序关联的所有工作。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.stopAndClearWorks](../js-apis-resourceschedule-workScheduler.md/#workschedulerstopandclearworks9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**示例** **示例**
```js ```js
try{ let res = workScheduler.stopAndClearWorks();
workScheduler.stopAndClearWorks(); console.info(`workschedulerLog res: ${res}`);
console.info(`workschedulerLog stopAndClearWorks success`);
} catch (error) {
console.error(`workschedulerLog stopAndClearWorks failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
...@@ -247,6 +258,10 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean ...@@ -247,6 +258,10 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
检查指定工作的最后一次执行是否为超时操作,使用Callback形式返回。 检查指定工作的最后一次执行是否为超时操作,使用Callback形式返回。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.isLastWorkTimeOut](../js-apis-resourceschedule-workScheduler.md/#workschedulerisLastworktimeoutcallback9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数** **参数**
...@@ -265,17 +280,13 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean ...@@ -265,17 +280,13 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
**示例** **示例**
```js ```js
try{ workScheduler.isLastWorkTimeOut(500, (err, res) =>{
workScheduler.isLastWorkTimeOut(500, (error, res) =>{ if (err) {
if (error) { console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`);
onsole.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
} else { } else {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
} }
}); });
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
...@@ -283,6 +294,10 @@ isLastWorkTimeOut(workId: number): Promise\<boolean> ...@@ -283,6 +294,10 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>
检查指定工作的最后一次执行是否为超时操作,使用Promise形式返回。 检查指定工作的最后一次执行是否为超时操作,使用Promise形式返回。
> **说明:** 从API version 9开始废弃,建议使用[workScheduler.isLastWorkTimeOut](../js-apis-resourceschedule-workScheduler.md/#workschedulerisLastworktimeoutpromise9)
>
> 从 API version 9开始支持。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler **系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数** **参数**
...@@ -300,17 +315,13 @@ isLastWorkTimeOut(workId: number): Promise\<boolean> ...@@ -300,17 +315,13 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>
**示例** **示例**
```js ```js
try{
workScheduler.isLastWorkTimeOut(500) workScheduler.isLastWorkTimeOut(500)
.then(res => { .then(res => {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
}) })
.catch(error => { .catch(err => {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`); console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`);
}); });
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## WorkInfo ## WorkInfo
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册