From 16d3aee03485bddd62a1f0e5212b12e26920d594 Mon Sep 17 00:00:00 2001 From: buzhuyu Date: Wed, 6 Sep 2023 18:31:11 +0800 Subject: [PATCH] =?UTF-8?q?fixed=204913ffb=20from=20https://gitee.com/buzh?= =?UTF-8?q?uyu/docs/pulls/24170=20sync-task=E6=96=87=E6=A1=A3arkTs?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: buzhuyu --- .../arkts-utils/sync-task-development.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/zh-cn/application-dev/arkts-utils/sync-task-development.md b/zh-cn/application-dev/arkts-utils/sync-task-development.md index 72b28a4325..0609d5eaa7 100644 --- a/zh-cn/application-dev/arkts-utils/sync-task-development.md +++ b/zh-cn/application-dev/arkts-utils/sync-task-development.md @@ -110,10 +110,10 @@ struct Index { .fontWeight(FontWeight.Bold) .onClick(() => { let w: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/MyWorker.ts'); - w.onmessage = () => { + w.onmessage = (): void => { // 接收Worker子线程的结果 } - w.onerror = () => { + w.onerror = (): void => { // 接收Worker子线程的错误信息 } // 向Worker子线程发送Set消息 @@ -145,15 +145,17 @@ struct Index { return; } } + ``` + ```ts // Worker.ts代码 import worker, { ThreadWorkerGlobalScope, MessageEvents } from '@ohos.worker'; - import Handle from './handle.ts' // 返回句柄 + import Handle from './handle' // 返回句柄 - var workerPort : ThreadWorkerGlobalScope = worker.workerPort; + let workerPort : ThreadWorkerGlobalScope = worker.workerPort; // 无法传输的句柄,所有操作依赖此句柄 - var handler = new Handle() + let handler: Handle = new Handle() // Worker线程的onmessage逻辑 workerPort.onmessage = (e : MessageEvents): void => { -- GitLab