Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
0571391d
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
164
Star
2
Fork
38
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
14
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
14
合并请求
14
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0571391d
编写于
12月 21, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update uts-for-android.md
上级
76e5a081
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
32 addition
and
6 deletion
+32
-6
docs/plugin/uts-for-android.md
docs/plugin/uts-for-android.md
+32
-6
未找到文件。
docs/plugin/uts-for-android.md
浏览文件 @
0571391d
...
...
@@ -120,15 +120,41 @@ class XXX{
### 2.4 线程环境差异
UTS环境中,默认是没有线程概念的。 代码默认执行在uts 单独的线程池中。
UTS环境中,默认是没有线程概念的。
如果需要执行异步任务,建议通过内置函数
`UTSAndroid.getDispatcher("io")`
执行
[
文档地址
](
https://doc.dcloud.net.cn/uni-app-x/uts/utsandroid.html#getdispatcher
)
如果需要执行异步任务,建议通过内置函数
`setTimeOut`
执行
```
ts
console
.
log
(
"
这里是UTS默认线程 :
"
+
Thread
.
currentThread
().
getName
())
setTimeOut
(
function
(){
console
.
log
(
"
这里是异步任务线程 :
"
+
Thread
.
currentThread
().
getName
())
},
1000
)
UTSAndroid
.
getDispatcher
(
"
main
"
).
async
(
function
(
_
){
if
(
Thread
.
currentThread
().
name
!=
'
main
'
){
callback
(
false
,
"
main thread error
"
)
return
}
UTSAndroid
.
getDispatcher
(
"
dom
"
).
async
(
function
(
_
){
/**
* dom 参数,只在2.0生效,1.0会自动切换到main线程
*/
if
(
Thread
.
currentThread
().
name
!=
'
main
'
&&
Thread
.
currentThread
().
name
!=
'
io_dcloud_uniapp_dom
'
){
callback
(
false
,
"
dom thread error
"
)
return
}
UTSAndroid
.
getDispatcher
(
"
io
"
).
async
(
function
(
_
){
/**
* dom 参数,只在2.0生效,1.0会自动切换到main线程
*/
if
(
!
Thread
.
currentThread
().
name
.
contains
(
"
DefaultDispatcher
"
)){
callback
(
false
,
"
io thread error
"
)
return
}
callback
(
true
,
"
pass
"
)
},
null
)
},
null
)
},
null
)
```
如果是android原生api 需要部分代码必须执行在UI线程,则需要通过原生api进行操作:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录