Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c2860746
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c2860746
编写于
2月 15, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 15, 2023
浏览文件
操作
浏览文件
下载
差异文件
!14370 add concurrent(worker and taskpool) doc
Merge pull request !14370 from wangzhaoyong/master
上级
1f38340d
c908555d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
78 addition
and
19 deletion
+78
-19
zh-cn/application-dev/reference/apis/js-apis-taskpool.md
zh-cn/application-dev/reference/apis/js-apis-taskpool.md
+46
-13
zh-cn/application-dev/reference/apis/js-apis-worker.md
zh-cn/application-dev/reference/apis/js-apis-worker.md
+32
-6
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-taskpool.md
浏览文件 @
c2860746
...
...
@@ -64,6 +64,7 @@ function func(args) {
console
.
log
(
"
func:
"
+
args
);
return
args
;
}
let
task
=
new
taskpool
.
Task
(
func
,
"
this is my first Task
"
);
```
...
...
@@ -116,7 +117,12 @@ function func(args) {
return
args
;
}
let
value
=
taskpool
.
execute
(
func
,
100
);
async
function
taskpoolTest
()
{
let
value
=
await
taskpool
.
execute
(
func
,
100
);
console
.
log
(
"
taskpool result:
"
+
value
);
}
taskpoolTest
();
```
## taskpool.execute
...
...
@@ -158,8 +164,14 @@ function func(args) {
console
.
log
(
"
func:
"
+
args
);
return
args
;
}
let
task
=
new
taskpool
.
Task
(
func
,
"
this is my first Task
"
);
let
value
=
taskpool
.
execute
(
task
);
async
function
taskpoolTest
()
{
let
task
=
new
taskpool
.
Task
(
func
,
100
);
let
value
=
await
taskpool
.
execute
(
task
);
console
.
log
(
"
taskpool result:
"
+
value
);
}
taskpoolTest
();
```
## taskpool.cancel
...
...
@@ -193,9 +205,14 @@ function func(args) {
console
.
log
(
"
func:
"
+
args
);
return
args
;
}
let
task
=
new
taskpool
.
Task
(
func
,
"
this is first Task
"
);
let
value
=
taskpool
.
execute
(
task
);
taskpool
.
cancel
(
task
);
async
function
taskpoolTest
()
{
let
task
=
new
taskpool
.
Task
(
func
,
100
);
let
value
=
await
taskpool
.
execute
(
task
);
taskpool
.
cancel
(
task
);
}
taskpoolTest
();
```
## 其他说明
...
...
@@ -214,10 +231,18 @@ function func(args) {
return
args
;
}
let
task
=
new
taskpool
.
Task
(
func
,
"
create task, then execute
"
);
let
val1
=
taskpool
.
execute
(
task
);
async
function
taskpoolTest
()
{
// taskpool.execute(task)
let
task
=
new
taskpool
.
Task
(
func
,
"
create task, then execute
"
);
let
val1
=
await
taskpool
.
execute
(
task
);
console
.
log
(
"
taskpool.execute(task) result:
"
+
val1
);
let
val2
=
taskpool
.
execute
(
func
,
"
execute task by func
"
);
// taskpool.execute(function)
let
val2
=
await
taskpool
.
execute
(
func
,
"
execute task by func
"
);
console
.
log
(
"
taskpool.execute(function) result:
"
+
val2
);
}
taskpoolTest
();
```
```
js
...
...
@@ -226,7 +251,7 @@ let val2 = taskpool.execute(func, "execute task by func");
// b.ts
export
var
c
=
2000
;
// a.ts
// a.ts
(与b.ts同目录)
import
{
c
}
from
'
./b
'
function
test
(
a
)
{
...
...
@@ -236,8 +261,16 @@ function test(a) {
return
a
;
}
let
task
=
new
taskpool
.
Task
(
test
,
"
create task, then execute
"
);
let
val1
=
taskpool
.
execute
(
task
);
async
function
taskpoolTest
()
{
// taskpool.execute(task)
let
task
=
new
taskpool
.
Task
(
test
,
"
create task, then execute
"
);
let
val1
=
await
taskpool
.
execute
(
task
);
console
.
log
(
"
taskpool.execute(task) result:
"
+
val1
);
// taskpool.execute(function)
let
val2
=
await
taskpool
.
execute
(
test
,
"
execute task by func
"
);
console
.
log
(
"
taskpool.execute(function) result:
"
+
val2
);
}
let
val2
=
taskpool
.
execute
(
test
,
"
execute task by func
"
);
taskpoolTest
(
);
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-worker.md
浏览文件 @
c2860746
...
...
@@ -81,19 +81,19 @@ ThreadWorker构造函数。
import
worker
from
'
@ohos.worker
'
;
// worker线程创建
// FA模型-目录同级
// FA模型-目录同级
(entry模块下,workers目录与pages目录同级)
const
workerFAModel01
=
new
worker
.
ThreadWorker
(
"
workers/worker.js
"
,
{
name
:
"
first worker in FA model
"
});
// FA模型-目录不同级(
以workers目录放置pages目录前一级为例
)
// FA模型-目录不同级(
entry模块下,workers目录与pages目录的父目录同级
)
const
workerFAModel02
=
new
worker
.
ThreadWorker
(
"
../workers/worker.js
"
);
// Stage模型-目录同级
// Stage模型-目录同级
(entry模块下,workers目录与pages目录同级)
const
workerStageModel01
=
new
worker
.
ThreadWorker
(
'
entry/ets/workers/worker.ts
'
,
{
name
:
"
first worker in Stage model
"
});
// Stage模型-目录不同级(
以workers目录放置pages目录后一级为例
)
// Stage模型-目录不同级(
entry模块下,workers目录是pages目录的子目录
)
const
workerStageModel02
=
new
worker
.
ThreadWorker
(
'
entry/ets/pages/workers/worker.ts
'
);
// 理解Stage模型scriptURL的"entry/ets/workers/worker.ts":
// entry: 为module.json5文件中module的name属性对应的值
;
//
ets: 表明当前使用的语言
。
// entry: 为module.json5文件中module的name属性对应的值
,ets: 表明当前使用的语言。
//
scriptURL与worker文件所在的workers目录层级有关,与new worker所在文件无关
。
```
同时,需在工程的模块级build-profile.json5文件的buildOption属性中添加配置信息,主要分为下面两种情况:
...
...
@@ -585,6 +585,15 @@ dispatchEvent(event: Event): boolean
```
js
const
workerInstance
=
new
worker
.
ThreadWorker
(
"
workers/worker.js
"
);
workerInstance
.
dispatchEvent
({
type
:
"
eventType
"
,
timeStamp
:
0
});
//timeStamp暂未支持。
```
分发事件(dispatchEvent)可与监听接口(on、once、addEventListener)搭配使用,示例如下:
```
js
const
workerInstance
=
new
worker
.
ThreadWorker
(
"
workers/worker.js
"
);
//用法一:
workerInstance
.
on
(
"
alert_on
"
,
(
e
)
=>
{
console
.
log
(
"
alert listener callback
"
);
...
...
@@ -751,6 +760,15 @@ dispatchEvent(event: Event): boolean
```
js
const
workerInstance
=
new
worker
.
ThreadWorker
(
"
workers/worker.js
"
);
workerInstance
.
dispatchEvent
({
type
:
"
eventType
"
,
timeStamp
:
0
});
//timeStamp暂未支持。
```
分发事件(dispatchEvent)可与监听接口(on、once、addEventListener)搭配使用,示例如下:
```
js
const
workerInstance
=
new
worker
.
ThreadWorker
(
"
workers/worker.js
"
);
//用法一:
workerInstance
.
on
(
"
alert_on
"
,
(
e
)
=>
{
console
.
log
(
"
alert listener callback
"
);
...
...
@@ -1593,6 +1611,14 @@ dispatchEvent(event: Event): boolean
```
js
const
workerInstance
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
workerInstance
.
dispatchEvent
({
type
:
"
eventType
"
,
timeStamp
:
0
});
//timeStamp暂未支持。
```
分发事件(dispatchEvent)可与监听接口(on、once、addEventListener)搭配使用,示例如下:
```
js
const
workerInstance
=
new
worker
.
Worker
(
"
workers/worker.js
"
);
//用法一:
workerInstance
.
on
(
"
alert_on
"
,
(
e
)
=>
{
console
.
log
(
"
alert listener callback
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录