• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS';
2
3const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
4
5/**
6 * Defines the event handler to be called when the worker thread receives a message sent by the host thread.
7 * The event handler is executed in the worker thread.
8 *
9 * @param e message data
10 */
11workerPort.onmessage = (e: MessageEvents) => {
12  let data = e.data as string;
13  if (data == 'onerror') {
14    throw new Error('Division by zero is not allowed.');
15  }
16}
17