From 003747f083de199e750ea560eeff0580b49c21a2 Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Wed, 28 May 2025 16:49:53 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20UseSendable=20=E4=BB=93=E5=BA=93=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UseSendable/entry/src/main/cpp/napi_init.cpp | 8 ++++---- .../pages/ConcurrencyCapabilitySelection1.ets | 2 +- .../ets/pages/ConcurrentTaskManagement5.ets | 6 +++--- .../ets/pages/InterthreadCommunication1.ets | 17 ++++++++++++++++- .../ets/pages/InterthreadCommunication2.ets | 1 + 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/UseSendable/entry/src/main/cpp/napi_init.cpp b/UseSendable/entry/src/main/cpp/napi_init.cpp index 89622ff0..be3f78cf 100644 --- a/UseSendable/entry/src/main/cpp/napi_init.cpp +++ b/UseSendable/entry/src/main/cpp/napi_init.cpp @@ -64,7 +64,7 @@ static void CallJs(napi_env env, napi_value jsCb, void *context, void *data) { } static void NativeThread(void *data) { CallbackData *callbackData = reinterpret_cast(data); - /* 跨线程调用*/ + /* Cross-thread call */ { assert(napi_acquire_threadsafe_function(callbackData->tsfn) == napi_ok); @@ -149,9 +149,9 @@ public: } private: - Singleton() {} // 私有构造函数,防止外部实例化对象 - Singleton(const Singleton &) = delete; // 禁止拷贝构造函数 - Singleton &operator=(const Singleton &) = delete; // 禁止赋值运算符 + Singleton() {} // Private constructor to prevent external instantiation of objects + Singleton(const Singleton &) = delete; // Do not copy the constructor + Singleton &operator=(const Singleton &) = delete; // The assignment operator is prohibited public: std::unordered_set numberSet_{}; diff --git a/UseSendable/entry/src/main/ets/pages/ConcurrencyCapabilitySelection1.ets b/UseSendable/entry/src/main/ets/pages/ConcurrencyCapabilitySelection1.ets index 74ed5c89..f558b5c0 100644 --- a/UseSendable/entry/src/main/ets/pages/ConcurrencyCapabilitySelection1.ets +++ b/UseSendable/entry/src/main/ets/pages/ConcurrencyCapabilitySelection1.ets @@ -24,7 +24,7 @@ async function foo(a: number, b: number) { return a + b; } -taskpool.execute(foo, 1, 2).then((ret: Object) => { // 结果处理 +taskpool.execute(foo, 1, 2).then((ret: Object) => { //Result processing console.log('Return:' + ret); }) // [End taskpool] \ No newline at end of file diff --git a/UseSendable/entry/src/main/ets/pages/ConcurrentTaskManagement5.ets b/UseSendable/entry/src/main/ets/pages/ConcurrentTaskManagement5.ets index 96bea6a3..bcf48326 100644 --- a/UseSendable/entry/src/main/ets/pages/ConcurrentTaskManagement5.ets +++ b/UseSendable/entry/src/main/ets/pages/ConcurrentTaskManagement5.ets @@ -17,11 +17,11 @@ * 最佳实践: 应用并发设计 并发任务管理 任务延时调度 */ // [Start quick_start] -import { concurrent_task } from '@kit.ArkTS'; +import { taskpool } from '@kit.ArkTS'; @Concurrent function concurrentTask(num: number): number { - console.log('这里添加需延时执行的任务'); + console.log('Add the task that needs to be executed with delay'); return num; } @@ -32,4 +32,4 @@ taskpool.executeDelayed(3000, task, taskpool.Priority.HIGH).then((value: Object) // Processing delayed task results console.log('taskpool result: ' + value); }); -// [End concurrent_task] \ No newline at end of file +// [End quick_start] \ No newline at end of file diff --git a/UseSendable/entry/src/main/ets/pages/InterthreadCommunication1.ets b/UseSendable/entry/src/main/ets/pages/InterthreadCommunication1.ets index 19346c98..cb4968e5 100644 --- a/UseSendable/entry/src/main/ets/pages/InterthreadCommunication1.ets +++ b/UseSendable/entry/src/main/ets/pages/InterthreadCommunication1.ets @@ -32,4 +32,19 @@ struct InterthreadCommunication1 { }) } } -// [End inter_thread_communication1] \ No newline at end of file +// [End inter_thread_communication1] + +@Component +struct TestCode { + // [Start index_btn] + // Index.ets + build() { + Button('click me') + .onClick(() => { + nativeModule.nativeCall((a: number) => { + console.log('Received data from thread-function: %{public}d', a); + }) + }) + } + // [End index_btn] +} \ No newline at end of file diff --git a/UseSendable/entry/src/main/ets/pages/InterthreadCommunication2.ets b/UseSendable/entry/src/main/ets/pages/InterthreadCommunication2.ets index 4773b0ef..c69a6bd3 100644 --- a/UseSendable/entry/src/main/ets/pages/InterthreadCommunication2.ets +++ b/UseSendable/entry/src/main/ets/pages/InterthreadCommunication2.ets @@ -17,6 +17,7 @@ * 最佳实践: 应用并发设计 线程间通信 线程间模块共享(单例模式) (方案一) */ // [Start store] +// Index.ets import { taskpool } from '@kit.ArkTS'; import singleton from 'libentry.so'; -- Gitee