• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit ArkTS
19 */
20
21/**
22 * @typedef WorkerOptions
23 * Provides options that can be set for the worker to create.
24 * @syscap SystemCapability.Utils.Lang
25 * @since 7
26 */
27/**
28 * @typedef WorkerOptions
29 * Provides options that can be set for the worker to create.
30 * @syscap SystemCapability.Utils.Lang
31 * @crossplatform
32 * @since 10
33 */
34/**
35 * @typedef WorkerOptions
36 * Provides options that can be set for the Worker instance to create.
37 * @syscap SystemCapability.Utils.Lang
38 * @crossplatform
39 * @atomicservice
40 * @since 11
41 */
42export interface WorkerOptions {
43  /**
44   * Mode in which the worker executes the script.
45   *
46   * @syscap SystemCapability.Utils.Lang
47   * @since 7
48   */
49  /**
50   * Mode in which the worker executes the script.
51   *
52   * @syscap SystemCapability.Utils.Lang
53   * @crossplatform
54   * @since 10
55   */
56  /**
57   * Mode in which the Worker instance executes the script. The module type is not supported yet. The default value is classic.
58   *
59   * @type { ?('classic' | 'module') }
60   * @syscap SystemCapability.Utils.Lang
61   * @crossplatform
62   * @atomicservice
63   * @since 11
64   */
65  type?: 'classic' | 'module';
66
67  /**
68   * Name of the worker.
69   *
70   * @syscap SystemCapability.Utils.Lang
71   * @since 7
72   */
73  /**
74   * Name of the worker.
75   *
76   * @syscap SystemCapability.Utils.Lang
77   * @crossplatform
78   * @since 10
79   */
80  /**
81   * Name of the Worker thread. The default value is undefined.
82   *
83   * @type { ?string }
84   * @syscap SystemCapability.Utils.Lang
85   * @crossplatform
86   * @atomicservice
87   * @since 11
88   */
89  name?: string;
90
91  /**
92   * Whether the worker is shared.
93   *
94   * @syscap SystemCapability.Utils.Lang
95   * @since 7
96   */
97  /**
98   * Whether the worker is shared.
99   *
100   * @syscap SystemCapability.Utils.Lang
101   * @crossplatform
102   * @since 10
103   */
104  /**
105   * Whether sharing of the Worker instance is enabled. Currently, sharing is not supported.
106   *
107   * @type { ?boolean }
108   * @syscap SystemCapability.Utils.Lang
109   * @crossplatform
110   * @atomicservice
111   * @since 12
112   */
113  shared?: boolean;
114
115  /**
116   * Priority of the Worker thread.
117   *
118   * @type { ?ThreadWorkerPriority }
119   * @syscap SystemCapability.Utils.Lang
120   * @atomicservice
121   * @since 18
122   */
123  priority?: ThreadWorkerPriority;
124}
125
126/**
127 * Enumerates the priorities available for Worker threads. For details about the mappings between priorities and QoS levels, see QoS Level.
128 *
129 * @enum { number } ThreadWorkerPriority
130 * @syscap SystemCapability.Utils.Lang
131 * @atomicservice
132 * @since 18
133 */
134export enum ThreadWorkerPriority {
135  /**
136   * High priority, corresponding to QOS_USER_INITIATED.
137   *
138   * @syscap SystemCapability.Utils.Lang
139   * @atomicservice
140   * @since 18
141   */
142  HIGH = 0,
143
144  /**
145   * Medium priority, corresponding to QOS_DEFAULT.
146   *
147   * @syscap SystemCapability.Utils.Lang
148   * @atomicservice
149   * @since 18
150   */
151  MEDIUM = 1,
152
153  /**
154   * Low priority, corresponding to QOS_UTILITY.
155   *
156   * @syscap SystemCapability.Utils.Lang
157   * @atomicservice
158   * @since 18
159   */
160  LOW = 2,
161
162  /**
163   * Background priority, corresponding to QOS_BACKGROUND.
164   *
165   * @syscap SystemCapability.Utils.Lang
166   * @atomicservice
167   * @since 18
168   */
169  IDLE = 3,
170
171  /**
172   * Deadline priority, corresponding to QOS_DEADLINE_REQUEST.
173   *
174   * @syscap SystemCapability.Utils.Lang
175   * @atomicservice
176   * @since 20
177   */
178  DEADLINE = 4,
179
180  /**
181   * Vip priority, corresponding to QOS_USER_INTERACTIVE.
182   *
183   * @syscap SystemCapability.Utils.Lang
184   * @atomicservice
185   * @since 20
186   */
187  VIP = 5
188}
189
190/**
191 * @typedef Event
192 * Defines the event.
193 * @syscap SystemCapability.Utils.Lang
194 * @since 7
195 */
196/**
197 * @typedef Event
198 * Defines the event.
199 * @syscap SystemCapability.Utils.Lang
200 * @crossplatform
201 * @since 10
202 */
203/**
204 * @typedef Event
205 * Defines the event.
206 * @syscap SystemCapability.Utils.Lang
207 * @crossplatform
208 * @atomicservice
209 * @since 11
210 */
211export interface Event {
212  /**
213   * Type of the Event.
214   *
215   * @syscap SystemCapability.Utils.Lang
216   * @since 7
217   */
218  /**
219   * Type of the Event.
220   *
221   * @syscap SystemCapability.Utils.Lang
222   * @crossplatform
223   * @since 10
224   */
225  /**
226   * Type of the Event.
227   *
228   * @type { string }
229   * @readonly
230   * @syscap SystemCapability.Utils.Lang
231   * @crossplatform
232   * @atomicservice
233   * @since 12
234   */
235  readonly type: string;
236
237  /**
238   * Timestamp(accurate to millisecond) when the event is created.
239   *
240   * @syscap SystemCapability.Utils.Lang
241   * @since 7
242   */
243  /**
244   * Timestamp(accurate to millisecond) when the event is created.
245   *
246   * @syscap SystemCapability.Utils.Lang
247   * @crossplatform
248   * @since 10
249   */
250  /**
251   * Timestamp (accurate to millisecond) when the event is created. This parameter is not supported yet.
252   *
253   * @type { number }
254   * @readonly
255   * @syscap SystemCapability.Utils.Lang
256   * @crossplatform
257   * @atomicservice
258   * @since 12
259   */
260  readonly timeStamp: number;
261}
262
263/**
264 * Provides detailed information about the exception occurred during worker execution.
265 * @typedef ErrorEvent
266 * @syscap SystemCapability.Utils.Lang
267 * @since 7
268 */
269/**
270 * Provides detailed information about the exception occurred during worker execution.
271 * @typedef ErrorEvent
272 * @syscap SystemCapability.Utils.Lang
273 * @crossplatform
274 * @since 10
275 */
276/**
277 * Provides detailed information about the exception that occurs during worker execution. The ErrorEvent class inherits from Event.
278 * @typedef ErrorEvent
279 * @extends Event
280 * @syscap SystemCapability.Utils.Lang
281 * @crossplatform
282 * @atomicservice
283 * @since 11
284 */
285export interface ErrorEvent extends Event {
286  /**
287   * Information about the exception.
288   *
289   * @syscap SystemCapability.Utils.Lang
290   * @since 7
291   */
292  /**
293   * Information about the exception.
294   *
295   * @syscap SystemCapability.Utils.Lang
296   * @crossplatform
297   * @since 10
298   */
299  /**
300   * Information about the exception.
301   *
302   * @type { string }
303   * @readonly
304   * @syscap SystemCapability.Utils.Lang
305   * @crossplatform
306   * @atomicservice
307   * @since 11
308   */
309  readonly message: string;
310
311  /**
312   * File where the exception is located.
313   *
314   * @syscap SystemCapability.Utils.Lang
315   * @since 7
316   */
317  /**
318   * File where the exception is located.
319   *
320   * @syscap SystemCapability.Utils.Lang
321   * @crossplatform
322   * @since 10
323   */
324  /**
325   * File where the exception is located.
326   *
327   * @type { string }
328   * @readonly
329   * @syscap SystemCapability.Utils.Lang
330   * @crossplatform
331   * @atomicservice
332   * @since 11
333   */
334  readonly filename: string;
335
336  /**
337   * Number of the line where the exception is located.
338   *
339   * @syscap SystemCapability.Utils.Lang
340   * @since 7
341   */
342  /**
343   * Number of the line where the exception is located.
344   *
345   * @syscap SystemCapability.Utils.Lang
346   * @crossplatform
347   * @since 10
348   */
349  /**
350   * Serial number of the line where the exception is located.
351   *
352   * @type { number }
353   * @readonly
354   * @syscap SystemCapability.Utils.Lang
355   * @crossplatform
356   * @atomicservice
357   * @since 11
358   */
359  readonly lineno: number;
360
361  /**
362   * Number of the column where the exception is located.
363   *
364   * @syscap SystemCapability.Utils.Lang
365   * @since 7
366   */
367  /**
368   * Number of the column where the exception is located.
369   *
370   * @syscap SystemCapability.Utils.Lang
371   * @crossplatform
372   * @since 10
373   */
374  /**
375   * Serial number of the column where the exception is located.
376   *
377   * @type { number }
378   * @readonly
379   * @syscap SystemCapability.Utils.Lang
380   * @crossplatform
381   * @atomicservice
382   * @since 11
383   */
384  readonly colno: number;
385
386  /**
387   * Type of the exception.
388   *
389   * @syscap SystemCapability.Utils.Lang
390   * @since 7
391   */
392  /**
393   * Type of the exception.
394   *
395   * @syscap SystemCapability.Utils.Lang
396   * @crossplatform
397   * @since 10
398   */
399  /**
400   * Type of the exception.
401   *
402   * @type { Object }
403   * @readonly
404   * @syscap SystemCapability.Utils.Lang
405   * @crossplatform
406   * @atomicservice
407   * @since 11
408   */
409  readonly error: Object;
410}
411
412/**
413 * Holds the data transferred between worker threads.
414 * @typedef MessageEvent<T>
415 * @syscap SystemCapability.Utils.Lang
416 * @since 7
417 */
418/**
419 * Holds the data transferred between worker threads.
420 * @typedef MessageEvent<T>
421 * @syscap SystemCapability.Utils.Lang
422 * @crossplatform
423 * @since 10
424 */
425/**
426 * Holds the data transferred between worker threads.
427 * @typedef MessageEvent<T>
428 * @extends Event
429 * @syscap SystemCapability.Utils.Lang
430 * @crossplatform
431 * @atomicservice
432 * @since 12
433 */
434export interface MessageEvent<T> extends Event {
435  /**
436   * Data transferred when an exception occurs.
437   *
438   * @syscap SystemCapability.Utils.Lang
439   * @since 7
440   */
441  /**
442   * Data transferred when an exception occurs.
443   *
444   * @syscap SystemCapability.Utils.Lang
445   * @crossplatform
446   * @since 10
447   */
448  /**
449   * Data transferred when an exception occurs.
450   *
451   * @type { T }
452   * @readonly
453   * @syscap SystemCapability.Utils.Lang
454   * @crossplatform
455   * @atomicservice
456   * @since 12
457   */
458  readonly data: T;
459}
460
461/**
462 * Saves the data transferred between worker thread and host thread.
463 * @typedef MessageEvents
464 * @syscap SystemCapability.Utils.Lang
465 * @since 9
466 */
467/**
468 * Saves the data transferred between worker thread and host thread.
469 * @typedef MessageEvents
470 * @syscap SystemCapability.Utils.Lang
471 * @crossplatform
472 * @since 10
473 */
474/**
475 * Holds the data transferred between Worker threads.
476 * @typedef MessageEvents
477 * @extends Event
478 * @syscap SystemCapability.Utils.Lang
479 * @crossplatform
480 * @atomicservice
481 * @since 11
482 */
483export interface MessageEvents extends Event {
484  /**
485   * Data transferred when an exception occurs.
486   *
487   * @type { any }
488   * @syscap SystemCapability.Utils.Lang
489   * @since 9
490   */
491  /**
492   * Data transferred when an exception occurs.
493   *
494   * @type { any }
495   * @syscap SystemCapability.Utils.Lang
496   * @crossplatform
497   * @since 10
498   */
499  /**
500   * Data transferred when an exception occurs.
501   *
502   * @type { any }
503   * @readonly
504   * @syscap SystemCapability.Utils.Lang
505   * @crossplatform
506   * @atomicservice
507   * @since 11
508   */
509  readonly data: any;
510}
511
512/**
513 * @typedef PostMessageOptions
514 * Specifies the object whose ownership need to be transferred during data transfer.
515 * The object must be ArrayBuffer.
516 * @syscap SystemCapability.Utils.Lang
517 * @since 7
518 */
519/**
520 * @typedef PostMessageOptions
521 * Specifies the object whose ownership need to be transferred during data transfer.
522 * The object must be ArrayBuffer.
523 * @syscap SystemCapability.Utils.Lang
524 * @crossplatform
525 * @since 10
526 */
527/**
528 * @typedef PostMessageOptions
529 * Defines the object for which the ownership is to be transferred during data transfer. The object must be an ArrayBuffer instance.
530 * After the ownership is transferred, the object becomes unavailable in the sender and can be used only in the receiver.
531 * @syscap SystemCapability.Utils.Lang
532 * @crossplatform
533 * @atomicservice
534 * @since 11
535 */
536export interface PostMessageOptions {
537  /**
538   * ArrayBuffer array used to transfer the ownership.
539   *
540   * @syscap SystemCapability.Utils.Lang
541   * @since 7
542   */
543  /**
544   * ArrayBuffer array used to transfer the ownership.
545   *
546   * @syscap SystemCapability.Utils.Lang
547   * @crossplatform
548   * @since 10
549   */
550  /**
551   * ArrayBuffer array used to transfer the ownership. The array cannot be null.
552   *
553   * @type { ?Object[] }
554   * @syscap SystemCapability.Utils.Lang
555   * @crossplatform
556   * @atomicservice
557   * @since 11
558   */
559  transfer?: Object[];
560}
561
562/**
563 * @typedef EventListener
564 * Implements event listening.
565 * @syscap SystemCapability.Utils.Lang
566 * @since 7
567 * @deprecated since 9
568 * @useinstead ohos.worker.WorkerEventListener
569 */
570export interface EventListener {
571  /**
572   * Specifies the callback to invoke.
573   *
574   * @param { Event } evt - evt evt Event class for the callback to invoke.
575   * @returns { void | Promise<void> }
576   * @syscap SystemCapability.Utils.Lang
577   * @since 7
578   * @deprecated since 9
579   * @useinstead ohos.worker.WorkerEventListener.(event: Event)
580   */
581  (evt: Event): void | Promise<void>;
582}
583
584/**
585 * @typedef WorkerEventListener
586 * Implements event listening.
587 * @syscap SystemCapability.Utils.Lang
588 * @since 9
589 */
590/**
591 * @typedef WorkerEventListener
592 * Implements event listening.
593 * @syscap SystemCapability.Utils.Lang
594 * @crossplatform
595 * @since 10
596 */
597/**
598 * @typedef WorkerEventListener
599 * Implements event listening.
600 * @syscap SystemCapability.Utils.Lang
601 * @crossplatform
602 * @atomicservice
603 * @since 12
604 */
605export interface WorkerEventListener {
606  /**
607   * Specifies the callback function to be invoked.
608   *
609   * @param { Event } event - event Event class for the callback to invoke.
610   * @returns { void | Promise<void> }
611   * @throws { BusinessError } 401 - Parameter error. Possible causes:
612   * 1.Mandatory parameters are left unspecified;
613   * 2.Incorrect parameter types;
614   * 3.Parameter verification failed.
615   * @throws { BusinessError } 10200004 - The Worker instance is not running.
616   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
617   * @syscap SystemCapability.Utils.Lang
618   * @since 9
619   */
620  /**
621   * Specifies the callback function to be invoked.
622   *
623   * @param { Event } event - event Event class for the callback to invoke.
624   * @returns { void | Promise<void> }
625   * @throws { BusinessError } 401 - Parameter error. Possible causes:
626   * 1.Mandatory parameters are left unspecified;
627   * 2.Incorrect parameter types;
628   * 3.Parameter verification failed.
629   * @throws { BusinessError } 10200004 - The Worker instance is not running.
630   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
631   * @syscap SystemCapability.Utils.Lang
632   * @crossplatform
633   * @since 10
634   */
635  /**
636   * Specifies the callback function to be invoked.
637   *
638   * @param { Event } event - Event class for the callback to invoke.
639   * @returns { void | Promise<void> }
640   * @throws { BusinessError } 401 - Parameter error. Possible causes:
641   * 1.Mandatory parameters are left unspecified;
642   * 2.Incorrect parameter types;
643   * 3.Parameter verification failed.
644   * @throws { BusinessError } 10200004 - Worker instance is not running.
645   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
646   * @syscap SystemCapability.Utils.Lang
647   * @crossplatform
648   * @atomicservice
649   * @since 12
650   */
651  (event: Event): void | Promise<void>;
652}
653
654/**
655 * Type of message, only "message" and "messageerror".
656 *
657 * @syscap SystemCapability.Utils.Lang
658 * @since 7
659 */
660/**
661 * Type of message, only "message" and "messageerror".
662 *
663 * @syscap SystemCapability.Utils.Lang
664 * @crossplatform
665 * @since 10
666 */
667/**
668 * Type of message, only "message" and "messageerror".
669 *
670 * @typedef { 'message' | 'messageerror' }
671 * @syscap SystemCapability.Utils.Lang
672 * @crossplatform
673 * @atomicservice
674 * @since 12
675 */
676type MessageType = 'message' | 'messageerror';
677
678/**
679 * @typedef EventTarget
680 * Specific event features.
681 * @syscap SystemCapability.Utils.Lang
682 * @since 7
683 * @deprecated since 9
684 * @useinstead ohos.worker.WorkerEventTarget
685 */
686export interface EventTarget {
687  /**
688   * Adds an event listener to the worker.
689   *
690   * @param { string } type - type Type of the event to listen for.
691   * @param { EventListener } listener - listener Callback to invoke when an event of the specified type occurs.
692   * @syscap SystemCapability.Utils.Lang
693   * @since 7
694   * @deprecated since 9
695   * @useinstead ohos.worker.WorkerEventTarget.addEventListener
696   */
697  addEventListener(type: string, listener: EventListener): void;
698
699  /**
700   * Dispatches the event defined for the worker.
701   *
702   * @param { Event } event - event Event to dispatch.
703   * @returns { boolean }
704   * @syscap SystemCapability.Utils.Lang
705   * @since 7
706   * @deprecated since 9
707   * @useinstead ohos.worker.WorkerEventTarget.dispatchEvent
708   */
709  dispatchEvent(event: Event): boolean;
710
711  /**
712   * Removes an event defined for the worker.
713   *
714   * @param { string } type - type Type of the event for which the event listener is removed.
715   * @param { EventListener } callback - callback Callback of the event listener to remove.
716   * @syscap SystemCapability.Utils.Lang
717   * @since 7
718   * @deprecated since 9
719   * @useinstead ohos.worker.WorkerEventTarget.removeEventListener
720   */
721  removeEventListener(type: string, callback?: EventListener): void;
722
723  /**
724   * Removes all event listeners for the worker.
725   *
726   * @syscap SystemCapability.Utils.Lang
727   * @since 7
728   * @deprecated since 9
729   * @useinstead ohos.worker.WorkerEventTarget.removeAllListener
730   */
731  removeAllListener(): void;
732}
733
734/**
735 * @typedef WorkerEventTarget
736 * Specific worker event features.
737 * @syscap SystemCapability.Utils.Lang
738 * @since 9
739 */
740/**
741 * @typedef WorkerEventTarget
742 * Specific worker event features.
743 * @syscap SystemCapability.Utils.Lang
744 * @crossplatform
745 * @since 10
746 */
747/**
748 * @typedef WorkerEventTarget
749 * Processes worker listening events.
750 * @syscap SystemCapability.Utils.Lang
751 * @crossplatform
752 * @atomicservice
753 * @since 11
754 */
755export interface WorkerEventTarget {
756  /**
757   * Adds an event listener to the worker.
758   *
759   * @param { string } type - type Type of the event to listen for.
760   * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
761   * @throws { BusinessError } 401 - Parameter error. Possible causes:
762   * 1.Mandatory parameters are left unspecified;
763   * 2.Incorrect parameter types;
764   * 3.Parameter verification failed.
765   * @throws { BusinessError } 10200004 - The Worker instance is not running.
766   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
767   * @syscap SystemCapability.Utils.Lang
768   * @since 9
769   */
770  /**
771   * Adds an event listener to the worker.
772   *
773   * @param { string } type - type Type of the event to listen for.
774   * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
775   * @throws { BusinessError } 401 - Parameter error. Possible causes:
776   * 1.Mandatory parameters are left unspecified;
777   * 2.Incorrect parameter types;
778   * 3.Parameter verification failed.
779   * @throws { BusinessError } 10200004 - The Worker instance is not running.
780   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
781   * @syscap SystemCapability.Utils.Lang
782   * @since 10
783   */
784  /**
785   * Adds an event listener to the worker.
786   *
787   * @param { string } type - type Type of the event to listen for.
788   * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
789   * @throws { BusinessError } 401 - Parameter error. Possible causes:
790   * 1.Mandatory parameters are left unspecified;
791   * 2.Incorrect parameter types;
792   * 3.Parameter verification failed.
793   * @throws { BusinessError } 10200004 - The Worker instance is not running.
794   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
795   * @syscap SystemCapability.Utils.Lang
796   * @crossplatform
797   * @since 11
798   */
799  /**
800   * Adds an event listener for the Worker thread. This API provides the same functionality as on9+.
801   *
802   * @param { string } type - type Type of the event to listen for.
803   * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
804   * @throws { BusinessError } 401 - Parameter error. Possible causes:
805   * 1.Mandatory parameters are left unspecified;
806   * 2.Incorrect parameter types;
807   * 3.Parameter verification failed.
808   * @throws { BusinessError } 10200004 - The Worker instance is not running.
809   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
810   * @syscap SystemCapability.Utils.Lang
811   * @crossplatform
812   * @atomicservice
813   * @since 12
814   */
815  addEventListener(type: string, listener: WorkerEventListener): void;
816  /**
817   * Handle the event defined for the worker.
818   *
819   * @param { Event } event - event Event to dispatch.
820   * @returns { boolean }
821   * @throws { BusinessError } 401 - Parameter error. Possible causes:
822   * 1.Mandatory parameters are left unspecified;
823   * 2.Incorrect parameter types;
824   * 3.Parameter verification failed.
825   * @throws { BusinessError } 10200004 - The Worker instance is not running.
826   * @syscap SystemCapability.Utils.Lang
827   * @since 9
828   */
829  /**
830   * Handle the event defined for the worker.
831   *
832   * @param { Event } event - event Event to dispatch.
833   * @returns { boolean }
834   * @throws { BusinessError } 401 - Parameter error. Possible causes:
835   * 1.Mandatory parameters are left unspecified;
836   * 2.Incorrect parameter types;
837   * 3.Parameter verification failed.
838   * @throws { BusinessError } 10200004 - The Worker instance is not running.
839   * @syscap SystemCapability.Utils.Lang
840   * @crossplatform
841   * @since 10
842   */
843  /**
844   * Dispatches the event defined for the Worker thread.
845   *
846   * @param { Event } event - event Event to dispatch.
847   * @returns { boolean }
848   * @throws { BusinessError } 401 - Parameter error. Possible causes:
849   * 1.Mandatory parameters are left unspecified;
850   * 2.Incorrect parameter types;
851   * 3.Parameter verification failed.
852   * @throws { BusinessError } 10200004 - The Worker instance is not running.
853   * @syscap SystemCapability.Utils.Lang
854   * @crossplatform
855   * @atomicservice
856   * @since 12
857   */
858  dispatchEvent(event: Event): boolean;
859  /**
860   * Remove an event defined for the worker.
861   *
862   * @param { string } type - type Type of the event for which the event listener is cancelled.
863   * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
864   * @throws { BusinessError } 401 - Parameter error. Possible causes:
865   * 1.Mandatory parameters are left unspecified;
866   * 2.Incorrect parameter types;
867   * 3.Parameter verification failed.
868   * @throws { BusinessError } 10200004 - The Worker instance is not running.
869   * @syscap SystemCapability.Utils.Lang
870   * @since 9
871   */
872  /**
873   * Remove an event defined for the worker.
874   *
875   * @param { string } type - type Type of the event for which the event listener is cancelled.
876   * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
877   * @throws { BusinessError } 401 - Parameter error. Possible causes:
878   * 1.Mandatory parameters are left unspecified;
879   * 2.Incorrect parameter types;
880   * 3.Parameter verification failed.
881   * @throws { BusinessError } 10200004 - The Worker instance is not running.
882   * @syscap SystemCapability.Utils.Lang
883   * @crossplatform
884   * @since 10
885   */
886  /**
887   * Removes an event listener for the Worker thread. This API provides the same functionality as off9+.
888   *
889   * @param { string } type - type Type of the event for which the event listener is to be removed.
890   * @param { WorkerEventListener } [callback] - callback Callback to invoke when the listener is removed.
891   * @throws { BusinessError } 401 - Parameter error. Possible causes:
892   * 1.Mandatory parameters are left unspecified;
893   * 2.Incorrect parameter types;
894   * 3.Parameter verification failed.
895   * @throws { BusinessError } 10200004 - The Worker instance is not running.
896   * @syscap SystemCapability.Utils.Lang
897   * @crossplatform
898   * @atomicservice
899   * @since 12
900   */
901  removeEventListener(type: string, callback?: WorkerEventListener): void;
902  /**
903   * Remove all event listeners for the worker.
904   *
905   * @throws { BusinessError } 10200004 - The Worker instance is not running.
906   * @syscap SystemCapability.Utils.Lang
907   * @since 9
908   */
909  /**
910   * Remove all event listeners for the worker.
911   *
912   * @throws { BusinessError } 10200004 - The Worker instance is not running.
913   * @syscap SystemCapability.Utils.Lang
914   * @crossplatform
915   * @since 10
916   */
917  /**
918   * Removes all event listeners for the Worker thread.
919   *
920   * @throws { BusinessError } 10200004 - The Worker instance is not running.
921   * @syscap SystemCapability.Utils.Lang
922   * @crossplatform
923   * @atomicservice
924   * @since 12
925   */
926  removeAllListener(): void;
927}
928
929/**
930 * @typedef WorkerGlobalScope
931 * Specifies the worker thread running environment, which is isolated from the host thread environment.
932 * @syscap SystemCapability.Utils.Lang
933 * @since 7
934 * @deprecated since 9
935 * @useinstead ohos.worker.GlobalScope
936 */
937declare interface WorkerGlobalScope extends EventTarget {
938  /**
939   * Worker name specified when there is a new worker.
940   *
941   * @syscap SystemCapability.Utils.Lang
942   * @since 7
943   * @deprecated since 9
944   * @useinstead ohos.worker.GlobalScope.name
945   */
946  readonly name: string;
947
948  /**
949   * The onerror attribute of parentPort specifies
950   * the event handler to be called when an exception occurs during worker execution.
951   * The event handler is executed in the worker thread.
952   *
953   * @syscap SystemCapability.Utils.Lang
954   * @since 7
955   * @deprecated since 9
956   * @useinstead ohos.worker.GlobalScope.onerror
957   */
958  onerror?: (ev: ErrorEvent) => void;
959
960  /**
961   * Specify the type attribute for self.
962   *
963   * @syscap SystemCapability.Utils.Lang
964   * @since 7
965   * @deprecated since 9
966   * @useinstead ohos.worker.GlobalScope.self
967   */
968  readonly self: WorkerGlobalScope & typeof globalThis;
969}
970
971/**
972 * The environment Specified in which worker threads run, which is isolated from the host thread environment.
973 * @typedef GlobalScope
974 * @syscap SystemCapability.Utils.Lang
975 * @since 9
976 */
977/**
978 * The environment Specified in which worker threads run, which is isolated from the host thread environment.
979 * @typedef GlobalScope
980 * @syscap SystemCapability.Utils.Lang
981 * @crossplatform
982 * @since 10
983 */
984/**
985 * Implements the running environment of the Worker thread. The GlobalScope class inherits from WorkerEventTarget.
986 * @typedef GlobalScope
987 * @extends WorkerEventTarget
988 * @syscap SystemCapability.Utils.Lang
989 * @crossplatform
990 * @atomicservice
991 * @since 11
992 */
993declare interface GlobalScope extends WorkerEventTarget {
994  /**
995   * Name of Worker specified when there is a new worker.
996   *
997   * @syscap SystemCapability.Utils.Lang
998   * @since 9
999   */
1000  /**
1001   * Name of Worker specified when there is a new worker.
1002   *
1003   * @syscap SystemCapability.Utils.Lang
1004   * @crossplatform
1005   * @since 10
1006   */
1007  /**
1008   * Worker instance specified when there is a new Worker instance.
1009   *
1010   * @type { string }
1011   * @readonly
1012   * @syscap SystemCapability.Utils.Lang
1013   * @crossplatform
1014   * @atomicservice
1015   * @since 11
1016   */
1017  readonly name: string;
1018
1019  /**
1020   * The onerror attribute of parentPort specified.
1021   * the event handler to be called when an exception occurs during worker execution.
1022   * The event handler is executed in the worker thread.
1023   *
1024   * @syscap SystemCapability.Utils.Lang
1025   * @since 9
1026   */
1027  /**
1028   * The onerror attribute of parentPort specified.
1029   * the event handler to be called when an exception occurs during worker execution.
1030   * The event handler is executed in the worker thread.
1031   *
1032   * @syscap SystemCapability.Utils.Lang
1033   * @crossplatform
1034   * @since 10
1035   */
1036  /**
1037   * Called when an exception occurs during worker execution. The event handler is executed in the Worker thread.
1038   * In the callback function, the ev type is ErrorEvent, indicating the received abnormal data.
1039   *
1040   * @type { ?function }
1041   * @syscap SystemCapability.Utils.Lang
1042   * @crossplatform
1043   * @atomicservice
1044   * @since 11
1045   */
1046  onerror?: (ev: ErrorEvent) => void;
1047  /**
1048   * Specify the type attribute for self.
1049   *
1050   * @syscap SystemCapability.Utils.Lang
1051   * @since 9
1052   */
1053  /**
1054   * Specify the type attribute for self.
1055   *
1056   * @syscap SystemCapability.Utils.Lang
1057   * @crossplatform
1058   * @since 10
1059   */
1060  /**
1061   * GlobalScope itself.
1062   *
1063   * @type { GlobalScope & typeof globalThis }
1064   * @readonly
1065   * @syscap SystemCapability.Utils.Lang
1066   * @crossplatform
1067   * @atomicservice
1068   * @since 11
1069   */
1070  readonly self: GlobalScope & typeof globalThis;
1071}
1072
1073/**
1074 * @typedef DedicatedWorkerGlobalScope
1075 * Specifies the worker thread running environment, which is isolated from the host thread environment
1076 * @syscap SystemCapability.Utils.Lang
1077 * @since 7
1078 * @deprecated since 9
1079 * @useinstead ohos.worker.ThreadWorkerGlobalScope
1080 */
1081export interface DedicatedWorkerGlobalScope extends WorkerGlobalScope {
1082  /**
1083   * The onmessage attribute of parentPort specifies the event handler
1084   * to be called then the worker thread receives a message sent by
1085   * the host thread through worker postMessage.
1086   * The event handler is executed in the worker thread.
1087   *
1088   * @syscap SystemCapability.Utils.Lang
1089   * @since 7
1090   * @deprecated since 9
1091   * @useinstead ohos.worker.ThreadWorkerGlobalScope.onmessage
1092   */
1093  onmessage?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) => void;
1094
1095  /**
1096   * The onmessage attribute of parentPort specifies the event handler
1097   * to be called then the worker receives a message that cannot be deserialized.
1098   * The event handler is executed in the worker thread.
1099   *
1100   * @syscap SystemCapability.Utils.Lang
1101   * @since 7
1102   * @deprecated since 9
1103   * @useinstead ohos.worker.ThreadWorkerGlobalScope.onmessageerror
1104   */
1105  onmessageerror?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) => void;
1106
1107  /**
1108   * Close the worker thread to stop the worker from receiving messages
1109   *
1110   * @syscap SystemCapability.Utils.Lang
1111   * @since 7
1112   * @deprecated since 9
1113   * @useinstead ohos.worker.ThreadWorkerGlobalScope.close
1114   */
1115  close(): void;
1116
1117  /**
1118   * Send a message to be host thread from the worker
1119   *
1120   * @param { Object } messageObject - messageObject Data to be sent to the worker
1121   * @param { Transferable[] } transfer - transfer array cannot contain null.
1122   * @syscap SystemCapability.Utils.Lang
1123   * @since 7
1124   * @deprecated since 9
1125   * @useinstead ohos.worker.ThreadWorkerGlobalScope.postMessage
1126   */
1127  postMessage(messageObject: Object, transfer: Transferable[]): void;
1128
1129  /**
1130   * Send a message to be host thread from the worker
1131   *
1132   * @param { Object } messageObject - messageObject Data to be sent to the worker
1133   * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
1134   * @syscap SystemCapability.Utils.Lang
1135   * @since 7
1136   * @deprecated since 9
1137   * @useinstead ohos.worker.ThreadWorkerGlobalScope.postMessage
1138   */
1139  postMessage(messageObject: Object, options?: PostMessageOptions): void;
1140
1141  /**
1142   * Send a message to host thread from the worker
1143   *
1144   * @param { Object } messageObject - messageObject Data to be sent to the worker
1145   * @param { ArrayBuffer[] } transfer - transfer array cannot contain null.
1146   * @syscap SystemCapability.Utils.Lang
1147   * @since 9
1148   * @deprecated since 9
1149   */
1150  postMessage(messageObject: Object, transfer: ArrayBuffer[]): void;
1151}
1152
1153/**
1154 * Specifies the thread-worker running environment, which is isolated from the host-thread environment
1155 * @typedef ThreadWorkerGlobalScope
1156 * @syscap SystemCapability.Utils.Lang
1157 * @since 9
1158 */
1159/**
1160 * Specifies the thread-worker running environment, which is isolated from the host-thread environment
1161 * @typedef ThreadWorkerGlobalScope
1162 * @syscap SystemCapability.Utils.Lang
1163 * @crossplatform
1164 * @since 10
1165 */
1166/**
1167 * Implements communication between the Worker thread and the host thread. The postMessage API is used to send messages
1168 * to the host thread, and the close API is used to terminate the Worker thread. The ThreadWorkerGlobalScope class inherits from GlobalScope9+.
1169 * @typedef ThreadWorkerGlobalScope
1170 * @extends GlobalScope
1171 * @syscap SystemCapability.Utils.Lang
1172 * @crossplatform
1173 * @atomicservice
1174 * @since 11
1175 */
1176export interface ThreadWorkerGlobalScope extends GlobalScope {
1177  /**
1178   * The onmessage attribute of parentPort specifies the event handler
1179   * to be called then the worker thread receives a message sent by
1180   * the host thread through worker postMessage.
1181   * The event handler is executed in the worker thread.
1182   *
1183   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1184   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1185   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1186   * @syscap SystemCapability.Utils.Lang
1187   * @since 9
1188   */
1189  /**
1190   * The onmessage attribute of parentPort specifies the event handler
1191   * to be called then the worker thread receives a message sent by
1192   * the host thread through worker postMessage.
1193   * The event handler is executed in the worker thread.
1194   *
1195   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1196   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1197   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1198   * @syscap SystemCapability.Utils.Lang
1199   * @crossplatform
1200   * @since 10
1201   */
1202  /**
1203   * Called when the Worker thread receives a message sent by the host thread through postMessage.
1204   * The event handler is executed in the Worker thread. In the callback function, this indicates the caller's
1205   * ThreadWorkerGlobalScope, and the ev type is MessageEvents, indicating the received message data.
1206   *
1207   * @type { ?function }
1208   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1209   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1210   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1211   * @syscap SystemCapability.Utils.Lang
1212   * @crossplatform
1213   * @atomicservice
1214   * @since 11
1215   */
1216  onmessage?: (this: ThreadWorkerGlobalScope, ev: MessageEvents) => void;
1217
1218  /**
1219   * The onmessage attribute of parentPort specifies the event handler
1220   * to be called then the worker receives a message that cannot be deserialized.
1221   * The event handler is executed in the worker thread.
1222   *
1223   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1224   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1225   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1226   * @syscap SystemCapability.Utils.Lang
1227   * @since 9
1228   */
1229  /**
1230   * The onmessage attribute of parentPort specifies the event handler
1231   * to be called then the worker receives a message that cannot be deserialized.
1232   * The event handler is executed in the worker thread.
1233   *
1234   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1235   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1236   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1237   * @syscap SystemCapability.Utils.Lang
1238   * @crossplatform
1239   * @since 10
1240   */
1241  /**
1242   * Called when the Worker thread receives a message that cannot be deserialized. The event handler is executed
1243   * in the Worker thread. In the callback function, this indicates the caller's ThreadWorkerGlobalScope,
1244   * and the ev type is MessageEvents, indicating the received message data.
1245   *
1246   * @type { ?function }
1247   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1248   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1249   * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1250   * @syscap SystemCapability.Utils.Lang
1251   * @crossplatform
1252   * @atomicservice
1253   * @since 11
1254   */
1255  onmessageerror?: (this: ThreadWorkerGlobalScope, ev: MessageEvents) => void;
1256
1257  /**
1258   * Close the worker thread to stop the worker from receiving messages
1259   *
1260   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1261   * @syscap SystemCapability.Utils.Lang
1262   * @since 9
1263   */
1264  /**
1265   * Close the worker thread to stop the worker from receiving messages
1266   *
1267   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1268   * @syscap SystemCapability.Utils.Lang
1269   * @crossplatform
1270   * @since 10
1271   */
1272  /**
1273   * Terminates the Worker thread to stop it from receiving messages.
1274   *
1275   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1276   * @syscap SystemCapability.Utils.Lang
1277   * @crossplatform
1278   * @atomicservice
1279   * @since 11
1280   */
1281  close(): void;
1282
1283  /**
1284   * Send a message to host thread from the worker
1285   *
1286   * @param { Object } messageObject - messageObject Data to be sent to the worker
1287   * @param { ArrayBuffer[] } transfer - transfer array cannot contain null.
1288   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1289   * 1.Mandatory parameters are left unspecified;
1290   * 2.Incorrect parameter types;
1291   * 3.Parameter verification failed.
1292   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1293   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1294   * @syscap SystemCapability.Utils.Lang
1295   * @since 9
1296   */
1297  /**
1298   * Send a message to host thread from the worker
1299   *
1300   * @param { Object } messageObject - messageObject Data to be sent to the worker
1301   * @param { ArrayBuffer[] } transfer - transfer array cannot contain null.
1302   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1303   * 1.Mandatory parameters are left unspecified;
1304   * 2.Incorrect parameter types;
1305   * 3.Parameter verification failed.
1306   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1307   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1308   * @syscap SystemCapability.Utils.Lang
1309   * @crossplatform
1310   * @since 10
1311   */
1312  /**
1313   * Sends a message from the Worker thread to the host thread by transferring object ownership.
1314   *
1315   * @param { Object } messageObject - Data to be sent to the host thread. The data object must be sequenceable.
1316   *     For details about the supported parameter types, see Sequenceable Data Types.
1317   * @param { ArrayBuffer[] } transfer - ArrayBuffer instance holding an array of objects for which the ownership
1318   *     is transferred to the host thread. After the transfer, the objects are available only in the host thread. The array cannot be null.
1319   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1320   * 1.Mandatory parameters are left unspecified;
1321   * 2.Incorrect parameter types;
1322   * 3.Parameter verification failed.
1323   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1324   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1325   * @syscap SystemCapability.Utils.Lang
1326   * @crossplatform
1327   * @atomicservice
1328   * @since 11
1329   */
1330  postMessage(messageObject: Object, transfer: ArrayBuffer[]): void;
1331
1332  /**
1333   * Send a message to be host thread from the worker
1334   *
1335   * @param { Object } messageObject - messageObject Data to be sent to the worker
1336   * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
1337   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1338   * 1.Mandatory parameters are left unspecified;
1339   * 2.Incorrect parameter types;
1340   * 3.Parameter verification failed.
1341   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1342   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1343   * @syscap SystemCapability.Utils.Lang
1344   * @since 9
1345   */
1346  /**
1347   * Send a message to be host thread from the worker
1348   *
1349   * @param { Object } messageObject - messageObject Data to be sent to the worker
1350   * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
1351   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1352   * 1.Mandatory parameters are left unspecified;
1353   * 2.Incorrect parameter types;
1354   * 3.Parameter verification failed.
1355   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1356   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1357   * @syscap SystemCapability.Utils.Lang
1358   * @crossplatform
1359   * @since 10
1360   */
1361  /**
1362   * Sends a message from the Worker thread to the host thread by transferring object ownership or copying data.
1363   *
1364   * @param { Object } messageObject - Data to be sent to the host thread. The data object must be sequenceable.
1365   *     For details about the supported parameter types, see Sequenceable Data Types.
1366   * @param { PostMessageOptions } [options] - If this parameter is specified, it functions the same as ArrayBuffer[].
1367   *     Specifically, the ownership of the objects in the array is transferred to the host thread and becomes unavailable in the Worker thread.
1368   *     The objects are available only in the host thread. If this parameter is not specified, the default value undefined is used,
1369   *     and information is transferred to the host thread by copying data.
1370   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1371   * 1.Mandatory parameters are left unspecified;
1372   * 2.Incorrect parameter types;
1373   * 3.Parameter verification failed.
1374   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1375   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1376   * @syscap SystemCapability.Utils.Lang
1377   * @crossplatform
1378   * @atomicservice
1379   * @since 11
1380   */
1381  postMessage(messageObject: Object, options?: PostMessageOptions): void;
1382
1383  /**
1384   * Sends a message from the Worker thread to the host thread. In the message, a sendable object is passed by reference,
1385   * and a non-sendable object is passed by serialization.
1386   *
1387   * @param { Object } message - Data to be sent to the host thread. The data object must be sequenceable or sendable.
1388   *     For details about the supported sequenceable types, see Sequenceable Data Types.
1389   *     For details about the supported sendable types, see Sendable Data Types.
1390   * @param { ArrayBuffer[] } [transfer] - ArrayBuffer instance holding an array of objects for which the ownership is
1391   *     transferred to the host thread. After the transfer, the objects are available only in the host thread.
1392   *     The array cannot be null. The default value is an empty array.
1393   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1394   * 1.Mandatory parameters are left unspecified;
1395   * 2.Incorrect parameter types;
1396   * 3.Parameter verification failed.
1397   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1398   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1399   * @syscap SystemCapability.Utils.Lang
1400   * @crossplatform
1401   * @atomicservice
1402   * @since 12
1403   */
1404  postMessageWithSharedSendable(message: Object, transfer?: ArrayBuffer[]): void;
1405
1406  /**
1407   * Send a global call on registered globalCallObject on host side and return the result synchronously
1408   *
1409   * @param { string } instanceName - the exact key used in registration
1410   * @param { string } methodName - a string which is same to the method called on globalCallObject.
1411   * @param { number } timeout - the specific milliseconds that will wait for result to return, between 0 and 5000.
1412   * @param { Object[] } args - the method argument called on registered globalCallObject.
1413   * @returns { Object } Return the result of method if it has a return value, otherwise return void.
1414   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1415   * 1.Mandatory parameters are left unspecified;
1416   * 2.Incorrect parameter types;
1417   * 3.Parameter verification failed.
1418   * @throws { BusinessError } 10200004 - The Worker instance is not running.
1419   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1420   * @throws { BusinessError } 10200019 - The globalCallObject is not registered.
1421   * @throws { BusinessError } 10200020 - The method to be called is not callable or is an async method or a generator.
1422   * @throws { BusinessError } 10200021 - Waiting for a global call timed out.
1423   * @syscap SystemCapability.Utils.Lang
1424   * @crossplatform
1425   * @since 11
1426   */
1427  /**
1428   * Calls a method of an object registered with the host thread. This API is called by the Worker thread.
1429   * The invoking is synchronous for the Worker thread and asynchronous for the host thread. The return value is transferred through serialization.
1430   *
1431   * @param { string } instanceName - Key used for registration. It is used to search for the object in the host thread.
1432   * @param { string } methodName - Name of the method to call. Note that the method cannot be modified by async or generator,
1433   *     or return results asynchronously by using the asynchronous mechanism at the bottom layer. Otherwise, an exception is thrown.
1434   * @param { number } timeout - Maximum duration that the current synchronous invoking waits, in ms.
1435   *     The value is an integer ranging from 1 to 5000. The value 0 means that the 5000 ms duration is used.
1436   * @param { Object[] } args - the method argument called on registered globalCallObject.
1437   * @returns { Object } Return the result of method if it has a return value, otherwise return void.
1438   * @throws { BusinessError } 401 - Parameter error. Possible causes:
1439   * 1.Mandatory parameters are left unspecified;
1440   * 2.Incorrect parameter types;
1441   * 3.Parameter verification failed.
1442   * @throws { BusinessError } 10200004 - Worker instance is not running.
1443   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1444   * @throws { BusinessError } 10200019 - The globalCallObject is not registered.
1445   * @throws { BusinessError } 10200020 - The method to be called is not callable or is an async method or a generator.
1446   * @throws { BusinessError } 10200021 - The global call exceeds the timeout.
1447   * @syscap SystemCapability.Utils.Lang
1448   * @crossplatform
1449   * @atomicservice
1450   * @since 12
1451   */
1452  callGlobalCallObjectMethod(instanceName: string, methodName: string, timeout: number, ...args: Object[]): Object;
1453}
1454
1455/**
1456 * The event handler to be called when an exception occurs during worker execution.
1457 *
1458 * @typedef { function } ErrorCallback
1459 * @param { ErrorEvent } err - Error event class, which provides detailed information about the exception occurred during Worker execution.
1460 * @returns { void }
1461 * @syscap SystemCapability.Utils.Lang
1462 * @atomicservice
1463 * @since 18
1464 */
1465type ErrorCallback = (err: ErrorEvent) => void;
1466
1467/**
1468 * JS cross-thread communication tool
1469 *
1470 * @namespace worker
1471 * @syscap SystemCapability.Utils.Lang
1472 * @since 7
1473 */
1474/**
1475 * JS cross-thread communication tool
1476 *
1477 * @namespace worker
1478 * @syscap SystemCapability.Utils.Lang
1479 * @crossplatform
1480 * @since 10
1481 */
1482/**
1483 * JS cross-thread communication tool
1484 *
1485 * @namespace worker
1486 * @syscap SystemCapability.Utils.Lang
1487 * @crossplatform
1488 * @atomicservice
1489 * @since 11
1490 */
1491declare namespace worker {
1492  /**
1493   * The ThreadWorker class contains all Worker functions.
1494   *
1495   * @syscap SystemCapability.Utils.Lang
1496   * @since 9
1497   */
1498  /**
1499   * The ThreadWorker class contains all Worker functions.
1500   *
1501   * @syscap SystemCapability.Utils.Lang
1502   * @crossplatform
1503   * @since 10
1504   */
1505  /**
1506   * Before using the following APIs, you must create a ThreadWorker instance. The ThreadWorker class inherits from WorkerEventTarget.
1507   *
1508   * @implements WorkerEventTarget
1509   * @syscap SystemCapability.Utils.Lang
1510   * @crossplatform
1511   * @atomicservice
1512   * @since 11
1513   */
1514  class ThreadWorker implements WorkerEventTarget {
1515    /**
1516     * Creates a worker instance
1517     *
1518     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
1519     * @param { WorkerOptions } [options] - options Options that can be set for the worker
1520     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1521     * 1.Mandatory parameters are left unspecified;
1522     * 2.Incorrect parameter types;
1523     * 3.Parameter verification failed.
1524     * @throws { BusinessError } 10200003 - Worker initialization failed.
1525     * @throws { BusinessError } 10200007 - The worker file path is invalid.
1526     * @syscap SystemCapability.Utils.Lang
1527     * @since 9
1528     */
1529    /**
1530     * Creates a worker instance
1531     *
1532     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
1533     * @param { WorkerOptions } [options] - options Options that can be set for the worker
1534     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1535     * 1.Mandatory parameters are left unspecified;
1536     * 2.Incorrect parameter types;
1537     * 3.Parameter verification failed.
1538     * @throws { BusinessError } 10200003 - Worker initialization failed.
1539     * @throws { BusinessError } 10200007 - The worker file path is invalid.
1540     * @syscap SystemCapability.Utils.Lang
1541     * @crossplatform
1542     * @since 10
1543     */
1544    /**
1545     * A constructor used to create a ThreadWorker instance.
1546     *
1547     * @param { string } scriptURL - URL of the Worker thread file. For details about the rules, see Precautions for File URLs.
1548     * @param { WorkerOptions } [options] - Options that can be set for the Worker instance.
1549     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1550     * 1.Mandatory parameters are left unspecified;
1551     * 2.Incorrect parameter types;
1552     * 3.Parameter verification failed.
1553     * @throws { BusinessError } 10200003 - Worker initialization failed.
1554     * @throws { BusinessError } 10200007 - The worker file path is invalid.
1555     * @syscap SystemCapability.Utils.Lang
1556     * @crossplatform
1557     * @atomicservice
1558     * @since 11
1559     */
1560    constructor(scriptURL: string, options?: WorkerOptions);
1561    /**
1562     * The onexit attribute of the worker specifies the event handler to be called
1563     * when the worker exits. The handler is executed in the host thread.
1564     *
1565     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1566     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1567     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1568     * @syscap SystemCapability.Utils.Lang
1569     * @since 9
1570     */
1571    /**
1572     * The onexit attribute of the worker specifies the event handler to be called
1573     * when the worker exits. The handler is executed in the host thread.
1574     *
1575     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1576     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1577     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1578     * @syscap SystemCapability.Utils.Lang
1579     * @crossplatform
1580     * @since 10
1581     */
1582    /**
1583     * Called when the Worker thread exits. The event handler is executed in the host thread. In the callback function,
1584     * the code value is of the number type, where the value 1 indicates abnormal exit and 0 indicates normal exit.
1585     *
1586     * @type { ?function }
1587     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1588     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1589     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1590     * @syscap SystemCapability.Utils.Lang
1591     * @crossplatform
1592     * @atomicservice
1593     * @since 11
1594     */
1595    onexit?: (code: number) => void;
1596    /**
1597     * The onerror attribute of the worker specifies the event handler to be called
1598     * when an exception occurs during worker execution.
1599     * The event handler is executed in the host thread.
1600     *
1601     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1602     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1603     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1604     * @syscap SystemCapability.Utils.Lang
1605     * @since 9
1606     */
1607    /**
1608     * The onerror attribute of the worker specifies the event handler to be called
1609     * when an exception occurs during worker execution.
1610     * The event handler is executed in the host thread.
1611     *
1612     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1613     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1614     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1615     * @syscap SystemCapability.Utils.Lang
1616     * @crossplatform
1617     * @since 10
1618     */
1619    /**
1620     * Called when an exception occurs during worker execution. The event handler is executed in the host thread.
1621     * In the callback function, the err type is ErrorEvent, indicating the received abnormal data.
1622     *
1623     * @type { ?function }
1624     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1625     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1626     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1627     * @syscap SystemCapability.Utils.Lang
1628     * @crossplatform
1629     * @atomicservice
1630     * @since 11
1631     */
1632    onerror?: (err: ErrorEvent) => void;
1633
1634    /**
1635     * Called when an exception occurs within the lifecycle of the Worker thread. The event handler is executed in the host thread.
1636     *
1637     * onerror can capture only exceptions generated by synchronous methods within the onmessage callback.
1638     * It cannot capture exceptions from multithreaded callbacks or modularization-related exceptions.
1639     * Once an exception is captured, the Worker thread will proceed to the destruction process and cannot be used.
1640     *
1641     * onAllErrors can capture global exceptions generated during the onmessage callback, timer callback,
1642     * and file execution of the Worker thread. After an exception is captured by onAllErrors,
1643     * the Worker thread remains alive and can continue to be used. You are advised to use onAllErrors instead of onerror.
1644     *
1645     * @type { ?function }
1646     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1647     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1648     * @syscap SystemCapability.Utils.Lang
1649     * @atomicservice
1650     * @since 18
1651     */
1652    onAllErrors?: ErrorCallback;
1653
1654    /**
1655     * The onmessage attribute of the worker specifies the event handler
1656     * to be called then the host thread receives a message created by itself
1657     * and sent by the worker through the parentPort.postMessage.
1658     * The event handler is executed in the host thread.
1659     *
1660     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1661     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1662     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1663     * @syscap SystemCapability.Utils.Lang
1664     * @since 9
1665     */
1666    /**
1667     * The onmessage attribute of the worker specifies the event handler
1668     * to be called then the host thread receives a message created by itself
1669     * and sent by the worker through the parentPort.postMessage.
1670     * The event handler is executed in the host thread.
1671     *
1672     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1673     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1674     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1675     * @syscap SystemCapability.Utils.Lang
1676     * @crossplatform
1677     * @since 10
1678     */
1679    /**
1680     * Called when the host thread receives a message sent by the Worker thread through workerPort.postMessage.
1681     * The event handler is executed in the host thread. In the callback function, the event type is MessageEvents, indicating the received message data.
1682     *
1683     * @type { ?function }
1684     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1685     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1686     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1687     * @syscap SystemCapability.Utils.Lang
1688     * @crossplatform
1689     * @atomicservice
1690     * @since 11
1691     */
1692    onmessage?: (event: MessageEvents) => void;
1693    /**
1694     * The onmessage attribute of the worker specifies the event handler
1695     * when the worker receives a message that cannot be serialized.
1696     * The event handler is executed in the host thread.
1697     *
1698     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1699     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1700     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1701     * @syscap SystemCapability.Utils.Lang
1702     * @since 9
1703     */
1704    /**
1705     * The onmessage attribute of the worker specifies the event handler
1706     * when the worker receives a message that cannot be serialized.
1707     * The event handler is executed in the host thread.
1708     *
1709     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1710     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1711     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1712     * @syscap SystemCapability.Utils.Lang
1713     * @crossplatform
1714     * @since 10
1715     */
1716    /**
1717     * Called when the Worker thread receives a message that cannot be serialized. The event handler is executed in the host thread.
1718     * In the callback function, the event type is MessageEvents, indicating the received message data.
1719     *
1720     * @type { ?function }
1721     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
1722     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1723     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1724     * @syscap SystemCapability.Utils.Lang
1725     * @crossplatform
1726     * @atomicservice
1727     * @since 11
1728     */
1729    onmessageerror?: (event: MessageEvents) => void;
1730    /**
1731     * Sends a message to the worker thread.
1732     * The data is transferred using the structured clone algorithm.
1733     *
1734     * @param { Object } message - message Data to be sent to the worker
1735     * @param { ArrayBuffer[] } transfer - transfer ArrayBuffer instance that can be transferred.
1736     * The transferList array cannot contain null.
1737     * @throws { BusinessError } 401 - if the input parameters are invalid.
1738     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1739     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1740     * @syscap SystemCapability.Utils.Lang
1741     * @since 9
1742     */
1743    /**
1744     * Sends a message to the worker thread.
1745     * The data is transferred using the structured clone algorithm.
1746     *
1747     * @param { Object } message - message Data to be sent to the worker
1748     * @param { ArrayBuffer[] } transfer - transfer ArrayBuffer instance that can be transferred.
1749     * The transferList array cannot contain null.
1750     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1751     * 1.Mandatory parameters are left unspecified;
1752     * 2.Incorrect parameter types;
1753     * 3.Parameter verification failed.
1754     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1755     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1756     * @syscap SystemCapability.Utils.Lang
1757     * @crossplatform
1758     * @since 10
1759     */
1760    /**
1761     * Sends a message from the host thread to the Worker thread by transferring object ownership.
1762     *
1763     * @param { Object } message - Data to be sent to the Worker thread. The data object must be sequenceable.
1764     *     For details about the supported parameter types, see Sequenceable Data Types.
1765     * @param { ArrayBuffer[] } transfer - ArrayBuffer instance holding an array of objects for which the ownership
1766     *     is transferred to the Worker thread. After the transfer, the objects are available only in the Worker thread. The array cannot be null.
1767     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1768     * 1.Mandatory parameters are left unspecified;
1769     * 2.Incorrect parameter types;
1770     * 3.Parameter verification failed.
1771     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1772     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1773     * @syscap SystemCapability.Utils.Lang
1774     * @crossplatform
1775     * @atomicservice
1776     * @since 11
1777     */
1778    postMessage(message: Object, transfer: ArrayBuffer[]): void;
1779    /**
1780     * Sends a message to the worker thread.
1781     * The data is transferred using the structured clone algorithm.
1782     *
1783     * @param { Object } message - message Data to be sent to the worker
1784     * @param { PostMessageOptions } [options] - options
1785     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1786     * 1.Mandatory parameters are left unspecified;
1787     * 2.Incorrect parameter types;
1788     * 3.Parameter verification failed.
1789     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1790     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1791     * @syscap SystemCapability.Utils.Lang
1792     * @since 9
1793     */
1794    /**
1795     * Sends a message to the worker thread.
1796     * The data is transferred using the structured clone algorithm.
1797     *
1798     * @param { Object } message - message Data to be sent to the worker
1799     * @param { PostMessageOptions } [options] - options
1800     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1801     * 1.Mandatory parameters are left unspecified;
1802     * 2.Incorrect parameter types;
1803     * 3.Parameter verification failed.
1804     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1805     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1806     * @syscap SystemCapability.Utils.Lang
1807     * @crossplatform
1808     * @since 10
1809     */
1810    /**
1811     * Sends a message from the host thread to the Worker thread by transferring object ownership or copying data.
1812     *
1813     * @param { Object } message - Data to be sent to the Worker thread. The data object must be sequenceable.
1814     *     For details about the supported parameter types, see Sequenceable Data Types.
1815     * @param { PostMessageOptions } [options] - If this parameter is specified, it functions the same as ArrayBuffer[].
1816     *     Specifically, the ownership of the objects in the array is transferred to the Worker thread and becomes unavailable in the host thread.
1817     *     The objects are available only in the Worker thread. If this parameter is not specified, the default value undefined is used,
1818     *     and information is transferred to the Worker thread by copying data.
1819     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1820     * 1.Mandatory parameters are left unspecified;
1821     * 2.Incorrect parameter types;
1822     * 3.Parameter verification failed.
1823     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1824     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1825     * @syscap SystemCapability.Utils.Lang
1826     * @crossplatform
1827     * @atomicservice
1828     * @since 11
1829     */
1830    postMessage(message: Object, options?: PostMessageOptions): void;
1831
1832    /**
1833     * Sends a message from the host thread to the Worker thread. In the message, a sendable object is passed by reference,
1834     * and a non-sendable object is passed by serialization.
1835     *
1836     * @param { Object } message - Data to be sent to the Worker thread. The data object must be sequenceable or sendable.
1837     *     For details about the supported sequenceable types, see Sequenceable Data Types.
1838     *     For details about the supported sendable types, see Sendable Data Types.
1839     * @param { ArrayBuffer[] } [transfer] - ArrayBuffer instance holding an array of objects for which the ownership
1840     *     is transferred to the Worker thread. After the transfer, the objects are available only in the Worker thread.
1841     *     The array cannot be null. The default value is an empty array.
1842     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1843     * 1.Mandatory parameters are left unspecified;
1844     * 2.Incorrect parameter types;
1845     * 3.Parameter verification failed.
1846     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1847     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1848     * @syscap SystemCapability.Utils.Lang
1849     * @crossplatform
1850     * @atomicservice
1851     * @since 12
1852     */
1853    postMessageWithSharedSendable(message: Object, transfer?: ArrayBuffer[]): void;
1854
1855    /**
1856     * Adds an event listener to the worker.
1857     *
1858     * @param { string } type - type Adds an event listener to the worker.
1859     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
1860     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1861     * 1.Mandatory parameters are left unspecified;
1862     * 2.Incorrect parameter types;
1863     * 3.Parameter verification failed.
1864     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1865     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1866     * @syscap SystemCapability.Utils.Lang
1867     * @since 9
1868     */
1869    /**
1870     * Adds an event listener to the worker.
1871     *
1872     * @param { string } type - type Adds an event listener to the worker.
1873     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
1874     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1875     * 1.Mandatory parameters are left unspecified;
1876     * 2.Incorrect parameter types;
1877     * 3.Parameter verification failed.
1878     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1879     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1880     * @syscap SystemCapability.Utils.Lang
1881     * @crossplatform
1882     * @since 10
1883     */
1884    /**
1885     * Adds an event listener for the Worker thread. This API provides the same functionality as addEventListener9+.
1886     *
1887     * @param { string } type - Type of the event to listen for.
1888     * @param { WorkerEventListener } listener - Callback to invoke when an event of the specified type occurs.
1889     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1890     * 1.Mandatory parameters are left unspecified;
1891     * 2.Incorrect parameter types;
1892     * 3.Parameter verification failed.
1893     * @throws { BusinessError } 10200004 - Worker instance is not running.
1894     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1895     * @syscap SystemCapability.Utils.Lang
1896     * @crossplatform
1897     * @atomicservice
1898     * @since 12
1899     */
1900    on(type: string, listener: WorkerEventListener): void;
1901    /**
1902     * Adds an event listener to the worker
1903     * and removes the event listener automatically after it is invoked once.
1904     *
1905     * @param { string } type - type Type of the event to listen for
1906     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs
1907     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1908     * 1.Mandatory parameters are left unspecified;
1909     * 2.Incorrect parameter types;
1910     * 3.Parameter verification failed.
1911     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1912     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1913     * @syscap SystemCapability.Utils.Lang
1914     * @since 9
1915     */
1916    /**
1917     * Adds an event listener to the worker
1918     * and removes the event listener automatically after it is invoked once.
1919     *
1920     * @param { string } type - type Type of the event to listen for
1921     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs
1922     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1923     * 1.Mandatory parameters are left unspecified;
1924     * 2.Incorrect parameter types;
1925     * 3.Parameter verification failed.
1926     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1927     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1928     * @syscap SystemCapability.Utils.Lang
1929     * @crossplatform
1930     * @since 10
1931     */
1932    /**
1933     * Adds an event listener for the Worker thread and removes the event listener after it is invoked once.
1934     *
1935     * @param { string } type - type Type of the event to listen for
1936     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs
1937     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1938     * 1.Mandatory parameters are left unspecified;
1939     * 2.Incorrect parameter types;
1940     * 3.Parameter verification failed.
1941     * @throws { BusinessError } 10200004 - Worker instance is not running.
1942     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1943     * @syscap SystemCapability.Utils.Lang
1944     * @crossplatform
1945     * @atomicservice
1946     * @since 12
1947     */
1948    once(type: string, listener: WorkerEventListener): void;
1949    /**
1950     * Removes an event listener to the worker.
1951     *
1952     * @param { string } type - type Type of the event for which the event listener is removed.
1953     * @param { WorkerEventListener } [listener] - listener Callback of the event listener to remove.
1954     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1955     * 1.Mandatory parameters are left unspecified;
1956     * 2.Incorrect parameter types;
1957     * 3.Parameter verification failed.
1958     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1959     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1960     * @syscap SystemCapability.Utils.Lang
1961     * @since 9
1962     */
1963    /**
1964     * Removes an event listener to the worker.
1965     *
1966     * @param { string } type - type Type of the event for which the event listener is removed.
1967     * @param { WorkerEventListener } [listener] - listener Callback of the event listener to remove.
1968     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1969     * 1.Mandatory parameters are left unspecified;
1970     * 2.Incorrect parameter types;
1971     * 3.Parameter verification failed.
1972     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1973     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
1974     * @syscap SystemCapability.Utils.Lang
1975     * @crossplatform
1976     * @since 10
1977     */
1978    /**
1979     * Removes an event listener for the Worker thread. This API provides the same functionality as removeEventListener9+.
1980     *
1981     * @param { string } type - type Type of the event for which the event listener is removed.
1982     * @param { WorkerEventListener } [listener] - listener Callback of the event listener to remove.
1983     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1984     * 1.Mandatory parameters are left unspecified;
1985     * 2.Incorrect parameter types;
1986     * 3.Parameter verification failed.
1987     * @throws { BusinessError } 10200004 - Worker instance is not running.
1988     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1989     * @syscap SystemCapability.Utils.Lang
1990     * @crossplatform
1991     * @atomicservice
1992     * @since 12
1993     */
1994    off(type: string, listener?: WorkerEventListener): void;
1995    /**
1996     * Terminates the worker thread to stop the worker from receiving messages
1997     *
1998     * @throws { BusinessError } 10200004 - The Worker instance is not running.
1999     * @syscap SystemCapability.Utils.Lang
2000     * @since 9
2001     */
2002    /**
2003     * Terminates the worker thread to stop the worker from receiving messages
2004     *
2005     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2006     * @syscap SystemCapability.Utils.Lang
2007     * @crossplatform
2008     * @since 10
2009     */
2010    /**
2011     * Terminates the Worker thread to stop it from receiving messages.
2012     *
2013     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2014     * @syscap SystemCapability.Utils.Lang
2015     * @crossplatform
2016     * @atomicservice
2017     * @since 11
2018     */
2019    terminate(): void;
2020    /**
2021     * Adds an event listener to the worker.
2022     *
2023     * @param { string } type - type Type of the event to listen for.
2024     * @param { WorkerEventListener } listener Callback to invoke when an event of the specified type occurs.
2025     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2026     * 1.Mandatory parameters are left unspecified;
2027     * 2.Incorrect parameter types;
2028     * 3.Parameter verification failed.
2029     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2030     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
2031     * @syscap SystemCapability.Utils.Lang
2032     * @since 9
2033     */
2034    /**
2035     * Adds an event listener to the worker.
2036     *
2037     * @param { string } type - type Type of the event to listen for.
2038     * @param { WorkerEventListener } listener Callback to invoke when an event of the specified type occurs.
2039     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2040     * 1.Mandatory parameters are left unspecified;
2041     * 2.Incorrect parameter types;
2042     * 3.Parameter verification failed.
2043     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2044     * @throws { BusinessError } 10200005 - The called API is not supported in the worker thread.
2045     * @syscap SystemCapability.Utils.Lang
2046     * @crossplatform
2047     * @since 10
2048     */
2049    /**
2050     * Adds an event listener for the Worker thread. This API provides the same functionality as on9+.
2051     *
2052     * @param { string } type - type Type of the event to listen for.
2053     * @param { WorkerEventListener } listener Callback to invoke when an event of the specified type occurs.
2054     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2055     * 1.Mandatory parameters are left unspecified;
2056     * 2.Incorrect parameter types;
2057     * 3.Parameter verification failed.
2058     * @throws { BusinessError } 10200004 - Worker instance is not running.
2059     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
2060     * @syscap SystemCapability.Utils.Lang
2061     * @crossplatform
2062     * @atomicservice
2063     * @since 12
2064     */
2065    addEventListener(type: string, listener: WorkerEventListener): void;
2066    /**
2067     * Handle the event defined for the worker.
2068     *
2069     * @param { Event } event - event Event to dispatch.
2070     * @returns { boolean }
2071     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2072     * 1.Mandatory parameters are left unspecified;
2073     * 2.Incorrect parameter types;
2074     * 3.Parameter verification failed.
2075     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2076     * @syscap SystemCapability.Utils.Lang
2077     * @since 9
2078     */
2079    /**
2080     * Handle the event defined for the worker.
2081     *
2082     * @param { Event } event - event Event to dispatch.
2083     * @returns { boolean }
2084     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2085     * 1.Mandatory parameters are left unspecified;
2086     * 2.Incorrect parameter types;
2087     * 3.Parameter verification failed.
2088     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2089     * @syscap SystemCapability.Utils.Lang
2090     * @crossplatform
2091     * @since 10
2092     */
2093    /**
2094     * Dispatches the event defined for the Worker thread.
2095     *
2096     * @param { Event } event - event Event to dispatch.
2097     * @returns { boolean }
2098     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2099     * 1.Mandatory parameters are left unspecified;
2100     * 2.Incorrect parameter types;
2101     * 3.Parameter verification failed.
2102     * @throws { BusinessError } 10200004 - Worker instance is not running.
2103     * @syscap SystemCapability.Utils.Lang
2104     * @crossplatform
2105     * @atomicservice
2106     * @since 12
2107     */
2108    dispatchEvent(event: Event): boolean;
2109    /**
2110     * Remove an event defined for the worker.
2111     *
2112     * @param { string } type - type Type of the event for which the event listener is cancelled.
2113     * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
2114     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2115     * 1.Mandatory parameters are left unspecified;
2116     * 2.Incorrect parameter types;
2117     * 3.Parameter verification failed.
2118     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2119     * @syscap SystemCapability.Utils.Lang
2120     * @since 9
2121     */
2122    /**
2123     * Remove an event defined for the worker.
2124     *
2125     * @param { string } type - type Type of the event for which the event listener is cancelled.
2126     * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
2127     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2128     * 1.Mandatory parameters are left unspecified;
2129     * 2.Incorrect parameter types;
2130     * 3.Parameter verification failed.
2131     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2132     * @syscap SystemCapability.Utils.Lang
2133     * @crossplatform
2134     * @since 10
2135     */
2136    /**
2137     * Removes an event listener for the Worker thread. This API provides the same functionality as off9+.
2138     *
2139     * @param { string } type - type Type of the event for which the event listener is to be removed.
2140     * @param { WorkerEventListener } [callback] - callback Callback to invoke when the listener is removed.
2141     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2142     * 1.Mandatory parameters are left unspecified;
2143     * 2.Incorrect parameter types;
2144     * 3.Parameter verification failed.
2145     * @throws { BusinessError } 10200004 - Worker instance is not running.
2146     * @syscap SystemCapability.Utils.Lang
2147     * @crossplatform
2148     * @atomicservice
2149     * @since 12
2150     */
2151    removeEventListener(type: string, callback?: WorkerEventListener): void;
2152    /**
2153     * Remove all event listeners for the worker.
2154     *
2155     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2156     * @syscap SystemCapability.Utils.Lang
2157     * @since 9
2158     */
2159    /**
2160     * Remove all event listeners for the worker.
2161     *
2162     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2163     * @syscap SystemCapability.Utils.Lang
2164     * @crossplatform
2165     * @since 10
2166     */
2167    /**
2168     * Removes all event listeners for the Worker thread.
2169     *
2170     * @throws { BusinessError } 10200004 - Worker instance is not running.
2171     * @syscap SystemCapability.Utils.Lang
2172     * @crossplatform
2173     * @atomicservice
2174     * @since 12
2175     */
2176    removeAllListener(): void;
2177
2178    /**
2179     * Register globalCallObject for global call.
2180     * @param { string } instanceName - The key to register globalCallObject.
2181     * @param { Object } globalCallObject - The globalCallObject that will be registered.
2182     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2183     * 1.Mandatory parameters are left unspecified;
2184     * 2.Incorrect parameter types;
2185     * 3.Parameter verification failed.
2186     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2187     * @syscap SystemCapability.Utils.Lang
2188     * @crossplatform
2189     * @since 11
2190     */
2191    /**
2192     * Registers an object with the ThreadWorker instance of the host thread.
2193     * In this way, the methods of the object can be called in the Worker thread through callGlobalCallObjectMethod.
2194     *
2195     * @param { string } instanceName - Key used for registration, based on which the registered object is identified during method calling.
2196     * @param { Object } globalCallObject - Object to register. The ThreadWorker instance holds a strong reference to the object.
2197     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2198     * 1.Mandatory parameters are left unspecified;
2199     * 2.Incorrect parameter types;
2200     * 3.Parameter verification failed.
2201     * @throws { BusinessError } 10200004 - Worker instance is not running.
2202     * @syscap SystemCapability.Utils.Lang
2203     * @crossplatform
2204     * @atomicservice
2205     * @since 12
2206     */
2207    registerGlobalCallObject(instanceName: string, globalCallObject: Object): void;
2208
2209    /**
2210     * Remove registered globalCallObject and release strong reference to registered object.
2211     * @param { string } [instanceName] - The exact key that used in registration.
2212     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2213     * 1.Mandatory parameters are left unspecified;
2214     * 2.Incorrect parameter types;
2215     * 3.Parameter verification failed.
2216     * @throws { BusinessError } 10200004 - The Worker instance is not running.
2217     * @syscap SystemCapability.Utils.Lang
2218     * @crossplatform
2219     * @since 11
2220     */
2221    /**
2222     * Unregisters an object with the ThreadWorker instance of the host thread. This API releases the strong reference
2223     * between the ThreadWorker instance and the target object. No error is reported if no object is matched.
2224     *
2225     * @param { string } [instanceName] - Key used for registration. If this parameter is left blank,
2226     *     all registered objects registered in the ThreadWorker instance are unregistered.
2227     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2228     * 1.Mandatory parameters are left unspecified;
2229     * 2.Incorrect parameter types;
2230     * 3.Parameter verification failed.
2231     * @throws { BusinessError } 10200004 - Worker instance is not running.
2232     * @syscap SystemCapability.Utils.Lang
2233     * @crossplatform
2234     * @atomicservice
2235     * @since 12
2236     */
2237    unregisterGlobalCallObject(instanceName?: string): void;
2238  }
2239
2240  /**
2241   * The RestrictedWorker class contains all Worker functions.
2242   *
2243   * @extends ThreadWorker
2244   * @syscap SystemCapability.Utils.Lang
2245   * @since 11
2246   */
2247  /**
2248   * The RestrictedWorker class contains all Worker functions.
2249   *
2250   * @extends ThreadWorker
2251   * @syscap SystemCapability.Utils.Lang
2252   * @systemapi
2253   * @since 12
2254   */
2255  class RestrictedWorker extends ThreadWorker {
2256    /**
2257     * Creates a worker instance
2258     *
2259     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
2260     * @param { WorkerOptions } [options] - options Options that can be set for the worker
2261     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2262     * 1.Mandatory parameters are left unspecified;
2263     * 2.Incorrect parameter types;
2264     * 3.Parameter verification failed.
2265     * @throws { BusinessError } 10200003 - Worker initialization failed.
2266     * @throws { BusinessError } 10200007 - The worker file path is invalid.
2267     * @syscap SystemCapability.Utils.Lang
2268     * @since 11
2269     */
2270    /**
2271     * Creates a worker instance
2272     *
2273     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
2274     * @param { WorkerOptions } [options] - options Options that can be set for the worker
2275     * @throws { BusinessError } 401 - Parameter error. Possible causes:
2276     * 1.Mandatory parameters are left unspecified;
2277     * 2.Incorrect parameter types;
2278     * 3.Parameter verification failed.
2279     * @throws { BusinessError } 10200003 - Worker initialization failure.
2280     * @throws { BusinessError } 10200007 - The worker file patch is invalid path.
2281     * @syscap SystemCapability.Utils.Lang
2282     * @systemapi
2283     * @since 12
2284     */
2285    constructor(scriptURL: string, options?: WorkerOptions);
2286  }
2287
2288  /**
2289   * The Worker class contains all Worker functions.
2290   *
2291   * @syscap SystemCapability.Utils.Lang
2292   * @since 7
2293   * @deprecated since 9
2294   * @useinstead ohos.worker.ThreadWorker
2295   */
2296  class Worker implements EventTarget {
2297    /**
2298     * Creates a worker instance
2299     *
2300     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
2301     * @param { WorkerOptions } options - options Options that can be set for the worker
2302     * @syscap SystemCapability.Utils.Lang
2303     * @since 7
2304     * @deprecated since 9
2305     * @useinstead ohos.worker.ThreadWorker.constructor
2306     */
2307    constructor(scriptURL: string, options?: WorkerOptions);
2308
2309    /**
2310     * The onexit attribute of the worker specifies the event handler to be called
2311     * when the worker exits. The handler is executed in the host thread.
2312     *
2313     * @syscap SystemCapability.Utils.Lang
2314     * @since 7
2315     * @deprecated since 9
2316     * @useinstead ohos.worker.ThreadWorker.onexit
2317     */
2318    onexit?: (code: number) => void;
2319
2320    /**
2321     * The onerror attribute of the worker specifies the event handler to be called
2322     * when an exception occurs during worker execution.
2323     * The event handler is executed in the host thread.
2324     *
2325     * @syscap SystemCapability.Utils.Lang
2326     * @since 7
2327     * @deprecated since 9
2328     * @useinstead ohos.worker.ThreadWorker.onerror
2329     */
2330    onerror?: (err: ErrorEvent) => void;
2331
2332    /**
2333     * The onmessage attribute of the worker specifies the event handler
2334     * to be called then the host thread receives a message created by itself
2335     * and sent by the worker through the parentPort.postMessage.
2336     * The event handler is executed in the host thread.
2337     *
2338     * @syscap SystemCapability.Utils.Lang
2339     * @since 7
2340     * @deprecated since 9
2341     * @useinstead ohos.worker.ThreadWorker.onmessage
2342     */
2343    onmessage?: (event: MessageEvent) => void;
2344
2345    /**
2346     * The onmessage attribute of the worker specifies the event handler
2347     * when the worker receives a message that cannot be serialized.
2348     * The event handler is executed in the host thread.
2349     *
2350     * @syscap SystemCapability.Utils.Lang
2351     * @since 7
2352     * @deprecated since 9
2353     * @useinstead ohos.worker.ThreadWorker.onmessageerror
2354     */
2355    onmessageerror?: (event: MessageEvent) => void;
2356
2357    /**
2358     * Sends a message to the worker thread.
2359     * The data is transferred using the structured clone algorithm.
2360     *
2361     * @param { Object } message - message - message Data to be sent to the worker
2362     * @param { ArrayBuffer[] } transfer - transfer ArrayBuffer instance that can be transferred.
2363     * The transferList array cannot contain null.
2364     * @syscap SystemCapability.Utils.Lang
2365     * @since 7
2366     * @deprecated since 9
2367     * @useinstead ohos.worker.ThreadWorker.postMessage
2368     */
2369    postMessage(message: Object, transfer: ArrayBuffer[]): void;
2370
2371    /**
2372     * Sends a message to the worker thread.
2373     * The data is transferred using the structured clone algorithm.
2374     *
2375     * @param { Object } message - message - message Data to be sent to the worker
2376     * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
2377     * The transferList array cannot contain null.
2378     * @syscap SystemCapability.Utils.Lang
2379     * @since 7
2380     * @deprecated since 9
2381     * @useinstead ohos.worker.ThreadWorker.postMessage
2382     */
2383    postMessage(message: Object, options?: PostMessageOptions): void;
2384
2385    /**
2386     * Adds an event listener to the worker.
2387     *
2388     * @param { string } type - type Adds an event listener to the worker.
2389     * @param { EventListener } listener - listener Callback to invoke when an event of the specified type occurs.
2390     * @syscap SystemCapability.Utils.Lang
2391     * @since 7
2392     * @deprecated since 9
2393     * @useinstead ohos.worker.ThreadWorker.on
2394     */
2395    on(type: string, listener: EventListener): void;
2396
2397    /**
2398     * Adds an event listener to the worker
2399     * and removes the event listener automatically after it is invoked once.
2400     *
2401     * @param { string } type - type Type of the event to listen for
2402     * @param { EventListener } listener - listener Callback to invoke when an event of the specified type occurs
2403     * @syscap SystemCapability.Utils.Lang
2404     * @since 7
2405     * @deprecated since 9
2406     * @useinstead ohos.worker.ThreadWorker.once
2407     */
2408    once(type: string, listener: EventListener): void;
2409
2410    /**
2411     * Removes an event listener to the worker.
2412     *
2413     * @param { string } type - type Type of the event for which the event listener is removed.
2414     * @param { EventListener } listener - listener Callback of the event listener to remove.
2415     * @syscap SystemCapability.Utils.Lang
2416     * @since 7
2417     * @deprecated since 9
2418     * @useinstead ohos.worker.ThreadWorker.off
2419     */
2420    off(type: string, listener?: EventListener): void;
2421
2422    /**
2423     * Terminates the worker thread to stop the worker from receiving messages
2424     *
2425     * @syscap SystemCapability.Utils.Lang
2426     * @since 7
2427     * @deprecated since 9
2428     * @useinstead ohos.worker.ThreadWorker.terminate
2429     */
2430    terminate(): void;
2431  }
2432
2433  /**
2434   * The object used by the worker thread to communicate with the host thread.
2435   *
2436   * @constant
2437   * @syscap SystemCapability.Utils.Lang
2438   * @since 7
2439   * @deprecated since 9
2440   * @useinstead ohos.worker.workerPort
2441   */
2442  const parentPort: DedicatedWorkerGlobalScope;
2443
2444  /**
2445   * The object used by the worker thread to communicate with the host thread.
2446   *
2447   * @constant
2448   * @syscap SystemCapability.Utils.Lang
2449   * @since 9
2450   */
2451  /**
2452   * The object used by the worker thread to communicate with the host thread.
2453   *
2454   * @constant
2455   * @syscap SystemCapability.Utils.Lang
2456   * @crossplatform
2457   * @since 10
2458   */
2459  /**
2460   * The object used by the worker thread to communicate with the host thread.
2461   *
2462   * @syscap SystemCapability.Utils.Lang
2463   * @crossplatform
2464   * @atomicservice
2465   * @since 11
2466   */
2467  const workerPort: ThreadWorkerGlobalScope;
2468}
2469export default worker;
2470