提交 1d4e173a 编写于 作者: 陈明

更新文档

Signed-off-by: N陈明 <chenming48@huawei.com>
上级 d986f905
...@@ -103,10 +103,10 @@ getWorkStatus(workId: number, callback : AsyncCallback<WorkInfo>): void ...@@ -103,10 +103,10 @@ getWorkStatus(workId: number, callback : AsyncCallback<WorkInfo>): void
``` ```
workScheduler.getWorkStatus(50, (err, res) => { workScheduler.getWorkStatus(50, (err, res) => {
if (err) { if (err) {
console.info('workschedulerLog getWorkStatus callback failed, because:' + err.data); console.info('workschedulerLog getWorkStatus failed, because:' + err.data);
} else { } else {
for (let item in res) { for (let item in res) {
console.info('workschedulerLog getWorkStatuscallback success,' + item + ' is:' + res[item]); console.info('workschedulerLog getWorkStatus success,' + item + ' is:' + res[item]);
} }
} }
}); });
...@@ -135,11 +135,10 @@ getWorkStatus(workID: number): Promise<WorkInfo> ...@@ -135,11 +135,10 @@ getWorkStatus(workID: number): Promise<WorkInfo>
``` ```
workScheduler.getWorkStatus(50).then((res) => { workScheduler.getWorkStatus(50).then((res) => {
for (let item in res) { for (let item in res) {
console.info('workschedulerLog getWorkStatuscallback success,' + item + ' is:' + res[item]); console.info('workschedulerLog getWorkStatus success,' + item + ' is:' + res[item]);
} }
}).catch((err) => { }).catch((err) => {
console.info('workschedulerLog getWorkStatus promise failed, err'); console.info('workschedulerLog getWorkStatus failed, because:' + err.data);
console.info('workschedulerLog getWorkStatus promise failed, because:' + err.data);
}) })
``` ```
...@@ -167,10 +166,9 @@ obtainAllWorks(callback : AsyncCallback<void>): Array<WorkInfo> ...@@ -167,10 +166,9 @@ obtainAllWorks(callback : AsyncCallback<void>): Array<WorkInfo>
``` ```
workScheduler.obtainAllWorks((err, res) =>{ workScheduler.obtainAllWorks((err, res) =>{
if (err) { if (err) {
console.info('workschedulerLog getWorkStatus promise failed, err'); console.info('workschedulerLog obtainAllWorks failed, because:' + err.data);
console.info('workschedulerLog getWorkStatus promise failed, because:' + err.data);
} else { } else {
console.info('workschedulerLog obtainAllWorks callback success, data is:' + JSON.stringify(res)); console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res));
} }
}); });
``` ```
...@@ -191,9 +189,9 @@ obtainAllWorks(): Promise<Array<WorkInfo>> ...@@ -191,9 +189,9 @@ obtainAllWorks(): Promise<Array<WorkInfo>>
``` ```
workScheduler.obtainAllWorks().then((res) => { workScheduler.obtainAllWorks().then((res) => {
console.info('workschedulerLog obtainAllWorks promise success, data is:' + JSON.stringify(res)); console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res));
}).catch((err) => { }).catch((err) => {
console.info('workschedulerLog obtainAllWorks promise failed, because:' + err.data); console.info('workschedulerLog obtainAllWorks failed, because:' + err.data);
}) })
``` ```
...@@ -234,9 +232,9 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback<void>): boolean ...@@ -234,9 +232,9 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback<void>): boolean
``` ```
workScheduler.isLastWorkTimeOut(500, (err, res) =>{ workScheduler.isLastWorkTimeOut(500, (err, res) =>{
if (err) { if (err) {
console.info('workschedulerLog isLastWorkTimeOut callback failed, because:' + err.data); console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data);
} else { } else {
console.info('workschedulerLog isLastWorkTimeOut callback success, data is:' + res); console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res);
} }
}); });
``` ```
...@@ -264,10 +262,10 @@ obtainAllWorks(): Promise<Array<WorkInfo>> ...@@ -264,10 +262,10 @@ obtainAllWorks(): Promise<Array<WorkInfo>>
``` ```
workScheduler.isLastWorkTimeOut(500) workScheduler.isLastWorkTimeOut(500)
.then(res => { .then(res => {
console.info('workschedulerLog isLastWorkTimeOut promise success, data is:' + res); console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res);
}) })
.catch(err => { .catch(err => {
console.info('workschedulerLog isLastWorkTimeOut promise failed, because:' + err.data); console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data);
}); });
}) })
``` ```
......
...@@ -112,13 +112,11 @@ function onWorkStop(work: WorkInfo): void; | 延迟调度任务结束回调 ...@@ -112,13 +112,11 @@ function onWorkStop(work: WorkInfo): void; | 延迟调度任务结束回调
**获取指定延迟任务** **获取指定延迟任务**
1.Callback写法
import workScheduler from '@ohos.workScheduler';
workScheduler.getWorkStatus(50, (err, res) => { workScheduler.getWorkStatus(50, (err, res) => {
if (err) { if (err) {
console.info('workschedulerLog getWorkStatus callback failed, because:' + err.data); console.info('workschedulerLog getWorkStatus failed, because:' + err.data);
} else { } else {
for (let item in res) { for (let item in res) {
console.info('workschedulerLog getWorkStatuscallback success,' + item + ' is:' + res[item]); console.info('workschedulerLog getWorkStatuscallback success,' + item + ' is:' + res[item]);
...@@ -126,31 +124,36 @@ function onWorkStop(work: WorkInfo): void; | 延迟调度任务结束回调 ...@@ -126,31 +124,36 @@ function onWorkStop(work: WorkInfo): void; | 延迟调度任务结束回调
} }
}); });
2.Promise写法
workScheduler.getWorkStatus(50).then((res) => { workScheduler.getWorkStatus(50).then((res) => {
for (let item in res) { for (let item in res) {
console.info('workschedulerLog getWorkStatuscallback success,' + item + ' is:' + res[item]); console.info('workschedulerLog getWorkStatus success,' + item + ' is:' + res[item]);
} }
}).catch((err) => { }).catch((err) => {
console.info('workschedulerLog getWorkStatus promise failed, err'); console.info('workschedulerLog getWorkStatus failed, because:' + err.data);
console.info('workschedulerLog getWorkStatus promise failed, because:' + err.data);
}) })
**获取所有延迟任务** **获取所有延迟任务**
1.Callback写法
workScheduler.obtainAllWorks((err, res) =>{ workScheduler.obtainAllWorks((err, res) =>{
if (err) { if (err) {
console.info('workschedulerLog getWorkStatus promise failed, err'); console.info('workschedulerLog obtainAllWorks failed, because:' + err.data);
console.info('workschedulerLog getWorkStatus promise failed, because:' + err.data);
} else { } else {
console.info('workschedulerLog obtainAllWorks callback success, data is:' + JSON.stringify(res)); console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res));
} }
}); });
2.Promise写法
workScheduler.obtainAllWorks().then((res) => { workScheduler.obtainAllWorks().then((res) => {
console.info('workschedulerLog obtainAllWorks promise success, data is:' + JSON.stringify(res)); console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res));
}).catch((err) => { }).catch((err) => {
console.info('workschedulerLog obtainAllWorks promise failed, because:' + err.data); console.info('workschedulerLog obtainAllWorks failed, because:' + err.data);
}) })
**停止并清除任务** **停止并清除任务**
...@@ -160,19 +163,23 @@ function onWorkStop(work: WorkInfo): void; | 延迟调度任务结束回调 ...@@ -160,19 +163,23 @@ function onWorkStop(work: WorkInfo): void; | 延迟调度任务结束回调
**判断上次执行是否超时** **判断上次执行是否超时**
1.Callback写法
workScheduler.isLastWorkTimeOut(500, (err, res) =>{ workScheduler.isLastWorkTimeOut(500, (err, res) =>{
if (err) { if (err) {
console.info('workschedulerLog isLastWorkTimeOut callback failed, because:' + err.data); console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data);
} else { } else {
console.info('workschedulerLog isLastWorkTimeOut callback success, data is:' + res); console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res);
} }
}); });
2.Promise写法
workScheduler.isLastWorkTimeOut(500) workScheduler.isLastWorkTimeOut(500)
.then(res => { .then(res => {
console.info('workschedulerLog isLastWorkTimeOut promise success, data is:' + res); console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res);
}) })
.catch(err => { .catch(err => {
console.info('workschedulerLog isLastWorkTimeOut promise failed, because:' + err.data); console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data);
}); });
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册