未验证 提交 321308f6 编写于 作者: O openharmony_ci 提交者: Gitee

!24170 sync-task文档arkTs整改

Merge pull request !24170 from buzhuyu/master
...@@ -110,10 +110,10 @@ struct Index { ...@@ -110,10 +110,10 @@ struct Index {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
.onClick(() => { .onClick(() => {
let w: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/MyWorker.ts'); let w: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/MyWorker.ts');
w.onmessage = () => { w.onmessage = (): void => {
// 接收Worker子线程的结果 // 接收Worker子线程的结果
} }
w.onerror = () => { w.onerror = (): void => {
// 接收Worker子线程的错误信息 // 接收Worker子线程的错误信息
} }
// 向Worker子线程发送Set消息 // 向Worker子线程发送Set消息
...@@ -145,15 +145,17 @@ struct Index { ...@@ -145,15 +145,17 @@ struct Index {
return; return;
} }
} }
```
```ts
// Worker.ts代码 // Worker.ts代码
import worker, { ThreadWorkerGlobalScope, MessageEvents } from '@ohos.worker'; 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逻辑 // Worker线程的onmessage逻辑
workerPort.onmessage = (e : MessageEvents): void => { workerPort.onmessage = (e : MessageEvents): void => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册