文件最后提交记录最后更新时间
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
update napi sample Issue: https://gitcode.com/HarmonyOS_Samples/guide-snippets/issues/452 Co-Authored-By: Agent Signed-off-by: tuxiaohang <tuxiaohang@huawei.com> 1 个月前
README.md

ArkTS使用Node-API接口进行异步任务开发

介绍

本工程展示了使用Node-API接口进行异步任务开发中的Promise方式和callback方式,详细描述可查如下链接。

效果预览

首页 执行结果图

使用说明

  1. 运行Index主界面。
  2. 页面呈现如上图效果,和两个按钮,依次点击按钮后可以调用Promise方式和callback方式的方法,并将结果呈现到text文本中,并在控制台中打印出对应日志。
  3. 运行测试用例NodeAPIAsynchronousTask.test.ets文件对页面代码进行测试可以全部通过。

工程目录

entry/src/
 ├── main
 │   ├── cpp
 │   │   ├── types
 │   │       ├── libentry
 │   │       └── libentry1
 │   │   ├── callback.cpp                // callback方式实现
 │   │   ├── CMakeLists.txt
 │   │   ├── napi_init.cpp               // Promise方式实现
 │   ├── ets
 │   │   ├── entryability
 │   │   ├── entrybackupability
 │   │   ├── pages
 │   │       ├── Index.ets               // 异步任务
 │   ├── module.json5
 │   └── resources
 ├── ohosTest
 │   ├── ets
 │   │   └── test
 │   │       ├── Ability.test.ets
 │   │       ├── NodeAPIAsynchronousTask.test.ets  // 自动化测试代码
 │   │       └── List.test.ets

相关权限

不涉及。

依赖

不涉及。

约束与限制

1.本示例仅支持标准系统上运行, 支持设备:RK3568。

2.本示例为Stage模型,支持API22版本SDK,版本号:6.0.0.57,镜像版本号:OpenHarmony_6.0.0.57。

3.本示例需要使用DevEco Studio 6.0.0 Release (Build Version: 6.0.0.858, built on October 21, 2025)及以上版本才可编译运行。

下载

如需单独下载本工程,执行如下命令:

git init
git config core.sparsecheckout true
echo code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask > .git/info/sparse-checkout
git remote add origin https://gitcode.com/openharmony/applications_app_samples.git
git pull origin master