• 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 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 executes the script.
58   *
59   * @syscap SystemCapability.Utils.Lang
60   * @crossplatform
61   * @atomicservice
62   * @since 11
63   */
64  type?: 'classic' | 'module';
65
66  /**
67   * Name of the worker.
68   *
69   * @syscap SystemCapability.Utils.Lang
70   * @since 7
71   */
72  /**
73   * Name of the worker.
74   *
75   * @syscap SystemCapability.Utils.Lang
76   * @crossplatform
77   * @since 10
78   */
79  /**
80   * Name of the worker.
81   *
82   * @syscap SystemCapability.Utils.Lang
83   * @crossplatform
84   * @atomicservice
85   * @since 11
86   */
87  name?: string;
88
89  /**
90   * Whether the worker is shared.
91   *
92   * @syscap SystemCapability.Utils.Lang
93   * @since 7
94   */
95  /**
96   * Whether the worker is shared.
97   *
98   * @syscap SystemCapability.Utils.Lang
99   * @crossplatform
100   * @since 10
101   */
102  shared?: boolean;
103}
104
105/**
106 * @typedef Event
107 * Defines the event.
108 * @syscap SystemCapability.Utils.Lang
109 * @since 7
110 */
111/**
112 * @typedef Event
113 * Defines the event.
114 * @syscap SystemCapability.Utils.Lang
115 * @crossplatform
116 * @since 10
117 */
118/**
119 * @typedef Event
120 * Defines the event.
121 * @syscap SystemCapability.Utils.Lang
122 * @crossplatform
123 * @atomicservice
124 * @since 11
125 */
126export interface Event {
127  /**
128   * Type of the Event.
129   *
130   * @syscap SystemCapability.Utils.Lang
131   * @since 7
132   */
133  /**
134   * Type of the Event.
135   *
136   * @syscap SystemCapability.Utils.Lang
137   * @crossplatform
138   * @since 10
139   */
140  readonly type: string;
141
142  /**
143   * Timestamp(accurate to millisecond) when the event is created.
144   *
145   * @syscap SystemCapability.Utils.Lang
146   * @since 7
147   */
148  /**
149   * Timestamp(accurate to millisecond) when the event is created.
150   *
151   * @syscap SystemCapability.Utils.Lang
152   * @crossplatform
153   * @since 10
154   */
155  readonly timeStamp: number;
156}
157
158/**
159 * @typedef ErrorEvent
160 * Provides detailed information about the exception occurred during worker execution.
161 * @syscap SystemCapability.Utils.Lang
162 * @since 7
163 */
164/**
165 * @typedef ErrorEvent
166 * Provides detailed information about the exception occurred during worker execution.
167 * @syscap SystemCapability.Utils.Lang
168 * @crossplatform
169 * @since 10
170 */
171/**
172 * @typedef ErrorEvent
173 * Provides detailed information about the exception occurred during worker execution.
174 * @syscap SystemCapability.Utils.Lang
175 * @crossplatform
176 * @atomicservice
177 * @since 11
178 */
179export interface ErrorEvent extends Event {
180  /**
181   * Information about the exception.
182   *
183   * @syscap SystemCapability.Utils.Lang
184   * @since 7
185   */
186  /**
187   * Information about the exception.
188   *
189   * @syscap SystemCapability.Utils.Lang
190   * @crossplatform
191   * @since 10
192   */
193  /**
194   * Information about the exception.
195   *
196   * @syscap SystemCapability.Utils.Lang
197   * @crossplatform
198   * @atomicservice
199   * @since 11
200   */
201  readonly message: string;
202
203  /**
204   * File where the exception is located.
205   *
206   * @syscap SystemCapability.Utils.Lang
207   * @since 7
208   */
209  /**
210   * File where the exception is located.
211   *
212   * @syscap SystemCapability.Utils.Lang
213   * @crossplatform
214   * @since 10
215   */
216  /**
217   * File where the exception is located.
218   *
219   * @syscap SystemCapability.Utils.Lang
220   * @crossplatform
221   * @atomicservice
222   * @since 11
223   */
224  readonly filename: string;
225
226  /**
227   * Number of the line where the exception is located.
228   *
229   * @syscap SystemCapability.Utils.Lang
230   * @since 7
231   */
232  /**
233   * Number of the line where the exception is located.
234   *
235   * @syscap SystemCapability.Utils.Lang
236   * @crossplatform
237   * @since 10
238   */
239  /**
240   * Number of the line where the exception is located.
241   *
242   * @syscap SystemCapability.Utils.Lang
243   * @crossplatform
244   * @atomicservice
245   * @since 11
246   */
247  readonly lineno: number;
248
249  /**
250   * Number of the column where the exception is located.
251   *
252   * @syscap SystemCapability.Utils.Lang
253   * @since 7
254   */
255  /**
256   * Number of the column where the exception is located.
257   *
258   * @syscap SystemCapability.Utils.Lang
259   * @crossplatform
260   * @since 10
261   */
262  /**
263   * Number of the column where the exception is located.
264   *
265   * @syscap SystemCapability.Utils.Lang
266   * @crossplatform
267   * @atomicservice
268   * @since 11
269   */
270  readonly colno: number;
271
272  /**
273   * Type of the exception.
274   *
275   * @syscap SystemCapability.Utils.Lang
276   * @since 7
277   */
278  /**
279   * Type of the exception.
280   *
281   * @syscap SystemCapability.Utils.Lang
282   * @crossplatform
283   * @since 10
284   */
285  /**
286   * Type of the exception.
287   *
288   * @syscap SystemCapability.Utils.Lang
289   * @crossplatform
290   * @atomicservice
291   * @since 11
292   */
293  readonly error: Object;
294}
295
296/**
297 * @typedef MessageEvent
298 * Holds the data transferred between worker threads.
299 * @syscap SystemCapability.Utils.Lang
300 * @since 7
301 */
302/**
303 * @typedef MessageEvent
304 * Holds the data transferred between worker threads.
305 * @syscap SystemCapability.Utils.Lang
306 * @crossplatform
307 * @since 10
308 */
309export interface MessageEvent<T> extends Event {
310  /**
311   * Data transferred when an exception occurs.
312   *
313   * @syscap SystemCapability.Utils.Lang
314   * @since 7
315   */
316  /**
317   * Data transferred when an exception occurs.
318   *
319   * @syscap SystemCapability.Utils.Lang
320   * @crossplatform
321   * @since 10
322   */
323  readonly data: T;
324}
325
326/**
327 * @typedef MessageEvents
328 * Saves the data transferred between worker thread and host thread.
329 * @syscap SystemCapability.Utils.Lang
330 * @since 9
331 */
332/**
333 * @typedef MessageEvents
334 * Saves the data transferred between worker thread and host thread.
335 * @syscap SystemCapability.Utils.Lang
336 * @crossplatform
337 * @since 10
338 */
339/**
340 * @typedef MessageEvents
341 * Saves the data transferred between worker thread and host thread.
342 * @syscap SystemCapability.Utils.Lang
343 * @crossplatform
344 * @atomicservice
345 * @since 11
346 */
347export interface MessageEvents extends Event {
348  /**
349   * Data transferred when an exception occurs.
350   *
351   * @syscap SystemCapability.Utils.Lang
352   * @since 9
353   */
354  /**
355   * Data transferred when an exception occurs.
356   *
357   * @syscap SystemCapability.Utils.Lang
358   * @crossplatform
359   * @since 10
360   */
361  /**
362   * Data transferred when an exception occurs.
363   *
364   * @syscap SystemCapability.Utils.Lang
365   * @crossplatform
366   * @atomicservice
367   * @since 11
368   */
369  readonly data;
370}
371
372/**
373 * @typedef PostMessageOptions
374 * Specifies the object whose ownership need to be transferred during data transfer.
375 * The object must be ArrayBuffer.
376 * @syscap SystemCapability.Utils.Lang
377 * @since 7
378 */
379/**
380 * @typedef PostMessageOptions
381 * Specifies the object whose ownership need to be transferred during data transfer.
382 * The object must be ArrayBuffer.
383 * @syscap SystemCapability.Utils.Lang
384 * @crossplatform
385 * @since 10
386 */
387/**
388 * @typedef PostMessageOptions
389 * Specifies the object whose ownership need to be transferred during data transfer.
390 * The object must be ArrayBuffer.
391 * @syscap SystemCapability.Utils.Lang
392 * @crossplatform
393 * @atomicservice
394 * @since 11
395 */
396export interface PostMessageOptions {
397  /**
398   * ArrayBuffer array used to transfer the ownership.
399   *
400   * @syscap SystemCapability.Utils.Lang
401   * @since 7
402   */
403  /**
404   * ArrayBuffer array used to transfer the ownership.
405   *
406   * @syscap SystemCapability.Utils.Lang
407   * @crossplatform
408   * @since 10
409   */
410  /**
411   * ArrayBuffer array used to transfer the ownership.
412   *
413   * @syscap SystemCapability.Utils.Lang
414   * @crossplatform
415   * @atomicservice
416   * @since 11
417   */
418  transfer?: Object[];
419}
420
421/**
422 * @typedef EventListener
423 * Implements event listening.
424 * @syscap SystemCapability.Utils.Lang
425 * @since 7
426 * @deprecated since 9
427 * @useinstead ohos.worker.WorkerEventListener
428 */
429export interface EventListener {
430  /**
431   * Specifies the callback to invoke.
432   *
433   * @param { Event } evt - evt evt Event class for the callback to invoke.
434   * @returns { void | Promise<void> }
435   * @syscap SystemCapability.Utils.Lang
436   * @since 7
437   * @deprecated since 9
438   * @useinstead ohos.worker.WorkerEventListener.(event: Event)
439   */
440  (evt: Event): void | Promise<void>;
441}
442
443/**
444 * @typedef WorkerEventListener
445 * Implements event listening.
446 * @syscap SystemCapability.Utils.Lang
447 * @since 9
448 */
449/**
450 * @typedef WorkerEventListener
451 * Implements event listening.
452 * @syscap SystemCapability.Utils.Lang
453 * @crossplatform
454 * @since 10
455 */
456export interface WorkerEventListener {
457  /**
458   * Specifies the callback function to be invoked.
459   *
460   * @param { Event } event - event Event class for the callback to invoke.
461   * @returns { void | Promise<void> }
462   * @throws { BusinessError } 401 - if the input parameters are invalid.
463   * @throws { BusinessError } 10200004 - Worker instance is not running.
464   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
465   * @syscap SystemCapability.Utils.Lang
466   * @since 9
467   */
468  /**
469   * Specifies the callback function to be invoked.
470   *
471   * @param { Event } event - event Event class for the callback to invoke.
472   * @returns { void | Promise<void> }
473   * @throws { BusinessError } 401 - if the input parameters are invalid.
474   * @throws { BusinessError } 10200004 - Worker instance is not running.
475   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
476   * @syscap SystemCapability.Utils.Lang
477   * @crossplatform
478   * @since 10
479   */
480  (event: Event): void | Promise<void>;
481}
482
483/**
484 * Type of message, only "message" and "messageerror".
485 *
486 * @syscap SystemCapability.Utils.Lang
487 * @since 7
488 */
489/**
490 * Type of message, only "message" and "messageerror".
491 *
492 * @syscap SystemCapability.Utils.Lang
493 * @crossplatform
494 * @since 10
495 */
496type MessageType = 'message' | 'messageerror';
497
498/**
499 * @typedef EventTarget
500 * Specific event features.
501 * @syscap SystemCapability.Utils.Lang
502 * @since 7
503 * @deprecated since 9
504 * @useinstead ohos.worker.WorkerEventTarget
505 */
506export interface EventTarget {
507  /**
508   * Adds an event listener to the worker.
509   *
510   * @param { string } type - type Type of the event to listen for.
511   * @param { EventListener } listener - listener Callback to invoke when an event of the specified type occurs.
512   * @syscap SystemCapability.Utils.Lang
513   * @since 7
514   * @deprecated since 9
515   * @useinstead ohos.worker.WorkerEventTarget.addEventListener
516   */
517  addEventListener(type: string, listener: EventListener): void;
518
519  /**
520   * Dispatches the event defined for the worker.
521   *
522   * @param { Event } event - event Event to dispatch.
523   * @returns { boolean }
524   * @syscap SystemCapability.Utils.Lang
525   * @since 7
526   * @deprecated since 9
527   * @useinstead ohos.worker.WorkerEventTarget.dispatchEvent
528   */
529  dispatchEvent(event: Event): boolean;
530
531  /**
532   * Removes an event defined for the worker.
533   *
534   * @param { string } type - type Type of the event for which the event listener is removed.
535   * @param { EventListener } callback - callback Callback of the event listener to remove.
536   * @syscap SystemCapability.Utils.Lang
537   * @since 7
538   * @deprecated since 9
539   * @useinstead ohos.worker.WorkerEventTarget.removeEventListener
540   */
541  removeEventListener(type: string, callback?: EventListener): void;
542
543  /**
544   * Removes all event listeners for the worker.
545   *
546   * @syscap SystemCapability.Utils.Lang
547   * @since 7
548   * @deprecated since 9
549   * @useinstead ohos.worker.WorkerEventTarget.removeAllListener
550   */
551  removeAllListener(): void;
552}
553
554/**
555 * @typedef WorkerEventTarget
556 * Specific worker event features.
557 * @syscap SystemCapability.Utils.Lang
558 * @since 9
559 */
560/**
561 * @typedef WorkerEventTarget
562 * Specific worker event features.
563 * @syscap SystemCapability.Utils.Lang
564 * @crossplatform
565 * @since 10
566 */
567/**
568 * @typedef WorkerEventTarget
569 * Specific worker event features.
570 * @syscap SystemCapability.Utils.Lang
571 * @crossplatform
572 * @atomicservice
573 * @since 11
574 */
575export interface WorkerEventTarget {
576  /**
577   * Adds an event listener to the worker.
578   *
579   * @param { string } type - type Type of the event to listen for.
580   * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
581   * @throws { BusinessError } 401 - if the input parameters are invalid.
582   * @throws { BusinessError } 10200004 - Worker instance is not running.
583   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
584   * @syscap SystemCapability.Utils.Lang
585   * @since 9
586   */
587  /**
588   * Adds an event listener to the worker.
589   *
590   * @param { string } type - type Type of the event to listen for.
591   * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
592   * @throws { BusinessError } 401 - if the input parameters are invalid.
593   * @throws { BusinessError } 10200004 - Worker instance is not running.
594   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
595   * @syscap SystemCapability.Utils.Lang
596   * @since 10
597   */
598  /**
599   * Adds an event listener to the worker.
600   *
601   * @param { string } type - type Type of the event to listen for.
602   * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
603   * @throws { BusinessError } 401 - if the input parameters are invalid.
604   * @throws { BusinessError } 10200004 - Worker instance is not running.
605   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
606   * @syscap SystemCapability.Utils.Lang
607   * @crossplatform
608   * @since 11
609   */
610  addEventListener(type: string, listener: WorkerEventListener): void;
611  /**
612   * Handle the event defined for the worker.
613   *
614   * @param { Event } event - event Event to dispatch.
615   * @returns { boolean }
616   * @throws { BusinessError } 401 - if the input parameters are invalid.
617   * @throws { BusinessError } 10200004 - Worker instance is not running.
618   * @syscap SystemCapability.Utils.Lang
619   * @since 9
620   */
621  /**
622   * Handle the event defined for the worker.
623   *
624   * @param { Event } event - event Event to dispatch.
625   * @returns { boolean }
626   * @throws { BusinessError } 401 - if the input parameters are invalid.
627   * @throws { BusinessError } 10200004 - Worker instance is not running.
628   * @syscap SystemCapability.Utils.Lang
629   * @crossplatform
630   * @since 10
631   */
632  dispatchEvent(event: Event): boolean;
633  /**
634   * Remove an event defined for the worker.
635   *
636   * @param { string } type - type Type of the event for which the event listener is cancelled.
637   * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
638   * @throws { BusinessError } 401 - if the input parameters are invalid.
639   * @throws { BusinessError } 10200004 - Worker instance is not running.
640   * @syscap SystemCapability.Utils.Lang
641   * @since 9
642   */
643  /**
644   * Remove an event defined for the worker.
645   *
646   * @param { string } type - type Type of the event for which the event listener is cancelled.
647   * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
648   * @throws { BusinessError } 401 - if the input parameters are invalid.
649   * @throws { BusinessError } 10200004 - Worker instance is not running.
650   * @syscap SystemCapability.Utils.Lang
651   * @crossplatform
652   * @since 10
653   */
654  removeEventListener(type: string, callback?: WorkerEventListener): void;
655  /**
656   * Remove all event listeners for the worker.
657   *
658   * @throws { BusinessError } 10200004 - Worker instance is not running.
659   * @syscap SystemCapability.Utils.Lang
660   * @since 9
661   */
662  /**
663   * Remove all event listeners for the worker.
664   *
665   * @throws { BusinessError } 10200004 - Worker instance is not running.
666   * @syscap SystemCapability.Utils.Lang
667   * @crossplatform
668   * @since 10
669   */
670  removeAllListener(): void;
671}
672
673/**
674 * @typedef WorkerGlobalScope
675 * Specifies the worker thread running environment, which is isolated from the host thread environment.
676 * @syscap SystemCapability.Utils.Lang
677 * @since 7
678 * @deprecated since 9
679 * @useinstead ohos.worker.GlobalScope
680 */
681declare interface WorkerGlobalScope extends EventTarget {
682  /**
683   * Worker name specified when there is a new worker.
684   *
685   * @syscap SystemCapability.Utils.Lang
686   * @since 7
687   * @deprecated since 9
688   * @useinstead ohos.worker.GlobalScope.name
689   */
690  readonly name: string;
691
692  /**
693   * The onerror attribute of parentPort specifies
694   * the event handler to be called when an exception occurs during worker execution.
695   * The event handler is executed in the worker thread.
696   *
697   * @syscap SystemCapability.Utils.Lang
698   * @since 7
699   * @deprecated since 9
700   * @useinstead ohos.worker.GlobalScope.onerror
701   */
702  onerror?: (ev: ErrorEvent) => void;
703
704  /**
705   * Specify the type attribute for self.
706   *
707   * @syscap SystemCapability.Utils.Lang
708   * @since 7
709   * @deprecated since 9
710   * @useinstead ohos.worker.GlobalScope.self
711   */
712  readonly self: WorkerGlobalScope & typeof globalThis;
713}
714
715/**
716 * @typedef GlobalScope
717 * The environment Specified in which worker threads run, which is isolated from the host thread environment.
718 * @syscap SystemCapability.Utils.Lang
719 * @since 9
720 */
721/**
722 * @typedef GlobalScope
723 * The environment Specified in which worker threads run, which is isolated from the host thread environment.
724 * @syscap SystemCapability.Utils.Lang
725 * @crossplatform
726 * @since 10
727 */
728/**
729 * @typedef GlobalScope
730 * The environment Specified in which worker threads run, which is isolated from the host thread environment.
731 * @syscap SystemCapability.Utils.Lang
732 * @crossplatform
733 * @atomicservice
734 * @since 11
735 */
736declare interface GlobalScope extends WorkerEventTarget {
737  /**
738   * Name of Worker specified when there is a new worker.
739   *
740   * @syscap SystemCapability.Utils.Lang
741   * @since 9
742   */
743  /**
744   * Name of Worker specified when there is a new worker.
745   *
746   * @syscap SystemCapability.Utils.Lang
747   * @crossplatform
748   * @since 10
749   */
750  /**
751   * Name of Worker specified when there is a new worker.
752   *
753   * @syscap SystemCapability.Utils.Lang
754   * @crossplatform
755   * @atomicservice
756   * @since 11
757   */
758  readonly name: string;
759
760  /**
761   * The onerror attribute of parentPort specified.
762   * the event handler to be called when an exception occurs during worker execution.
763   * The event handler is executed in the worker thread.
764   *
765   * @syscap SystemCapability.Utils.Lang
766   * @since 9
767   */
768  /**
769   * The onerror attribute of parentPort specified.
770   * the event handler to be called when an exception occurs during worker execution.
771   * The event handler is executed in the worker thread.
772   *
773   * @syscap SystemCapability.Utils.Lang
774   * @crossplatform
775   * @since 10
776   */
777  /**
778   * The onerror attribute of parentPort specified.
779   * the event handler to be called when an exception occurs during worker execution.
780   * The event handler is executed in the worker thread.
781   *
782   * @syscap SystemCapability.Utils.Lang
783   * @crossplatform
784   * @atomicservice
785   * @since 11
786   */
787  onerror?: (ev: ErrorEvent) => void;
788  /**
789   * Specify the type attribute for self.
790   *
791   * @syscap SystemCapability.Utils.Lang
792   * @since 9
793   */
794  /**
795   * Specify the type attribute for self.
796   *
797   * @syscap SystemCapability.Utils.Lang
798   * @crossplatform
799   * @since 10
800   */
801  /**
802   * Specify the type attribute for self.
803   *
804   * @syscap SystemCapability.Utils.Lang
805   * @crossplatform
806   * @atomicservice
807   * @since 11
808   */
809  readonly self: GlobalScope & typeof globalThis;
810}
811
812/**
813 * @typedef DedicatedWorkerGlobalScope
814 * Specifies the worker thread running environment, which is isolated from the host thread environment
815 * @syscap SystemCapability.Utils.Lang
816 * @since 7
817 * @deprecated since 9
818 * @useinstead ohos.worker.ThreadWorkerGlobalScope
819 */
820export interface DedicatedWorkerGlobalScope extends WorkerGlobalScope {
821  /**
822   * The onmessage attribute of parentPort specifies the event handler
823   * to be called then the worker thread receives a message sent by
824   * the host thread through worker postMessage.
825   * The event handler is executed in the worker thread.
826   *
827   * @syscap SystemCapability.Utils.Lang
828   * @since 7
829   * @deprecated since 9
830   * @useinstead ohos.worker.ThreadWorkerGlobalScope.onmessage
831   */
832  onmessage?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) => void;
833
834  /**
835   * The onmessage attribute of parentPort specifies the event handler
836   * to be called then the worker receives a message that cannot be deserialized.
837   * The event handler is executed in the worker thread.
838   *
839   * @syscap SystemCapability.Utils.Lang
840   * @since 7
841   * @deprecated since 9
842   * @useinstead ohos.worker.ThreadWorkerGlobalScope.onmessageerror
843   */
844  onmessageerror?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) => void;
845
846  /**
847   * Close the worker thread to stop the worker from receiving messages
848   *
849   * @syscap SystemCapability.Utils.Lang
850   * @since 7
851   * @deprecated since 9
852   * @useinstead ohos.worker.ThreadWorkerGlobalScope.close
853   */
854  close(): void;
855
856  /**
857   * Send a message to be host thread from the worker
858   *
859   * @param { Object } messageObject - messageObject Data to be sent to the worker
860   * @param { Transferable[] } transfer - transfer array cannot contain null.
861   * @syscap SystemCapability.Utils.Lang
862   * @since 7
863   * @deprecated since 9
864   * @useinstead ohos.worker.ThreadWorkerGlobalScope.postMessage
865   */
866  postMessage(messageObject: Object, transfer: Transferable[]): void;
867
868  /**
869   * Send a message to be host thread from the worker
870   *
871   * @param { Object } messageObject - messageObject Data to be sent to the worker
872   * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
873   * @syscap SystemCapability.Utils.Lang
874   * @since 7
875   * @deprecated since 9
876   * @useinstead ohos.worker.ThreadWorkerGlobalScope.postMessage
877   */
878  postMessage(messageObject: Object, options?: PostMessageOptions): void;
879
880  /**
881   * Send a message to host thread from the worker
882   *
883   * @param { Object } messageObject - messageObject Data to be sent to the worker
884   * @param { ArrayBuffer[] } transfer - transfer array cannot contain null.
885   * @syscap SystemCapability.Utils.Lang
886   * @since 9
887   * @deprecated since 9
888   */
889  postMessage(messageObject: Object, transfer: ArrayBuffer[]): void;
890}
891
892/**
893 * @typedef ThreadWorkerGlobalScope
894 * Specifies the thread-worker running environment, which is isolated from the host-thread environment
895 * @syscap SystemCapability.Utils.Lang
896 * @since 9
897 */
898/**
899 * @typedef ThreadWorkerGlobalScope
900 * Specifies the thread-worker running environment, which is isolated from the host-thread environment
901 * @syscap SystemCapability.Utils.Lang
902 * @crossplatform
903 * @since 10
904 */
905/**
906 * @typedef ThreadWorkerGlobalScope
907 * Specifies the thread-worker running environment, which is isolated from the host-thread environment
908 * @syscap SystemCapability.Utils.Lang
909 * @crossplatform
910 * @atomicservice
911 * @since 11
912 */
913export interface ThreadWorkerGlobalScope extends GlobalScope {
914  /**
915   * The onmessage attribute of parentPort specifies the event handler
916   * to be called then the worker thread receives a message sent by
917   * the host thread through worker postMessage.
918   * The event handler is executed in the worker thread.
919   *
920   * @throws { BusinessError } 401 - if the input parameters are invalid.
921   * @throws { BusinessError } 10200004 - Worker instance is not running.
922   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
923   * @syscap SystemCapability.Utils.Lang
924   * @since 9
925   */
926  /**
927   * The onmessage attribute of parentPort specifies the event handler
928   * to be called then the worker thread receives a message sent by
929   * the host thread through worker postMessage.
930   * The event handler is executed in the worker thread.
931   *
932   * @throws { BusinessError } 401 - if the input parameters are invalid.
933   * @throws { BusinessError } 10200004 - Worker instance is not running.
934   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
935   * @syscap SystemCapability.Utils.Lang
936   * @crossplatform
937   * @since 10
938   */
939  /**
940   * The onmessage attribute of parentPort specifies the event handler
941   * to be called then the worker thread receives a message sent by
942   * the host thread through worker postMessage.
943   * The event handler is executed in the worker thread.
944   *
945   * @throws { BusinessError } 401 - if the input parameters are invalid.
946   * @throws { BusinessError } 10200004 - Worker instance is not running.
947   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
948   * @syscap SystemCapability.Utils.Lang
949   * @crossplatform
950   * @atomicservice
951   * @since 11
952   */
953  onmessage?: (this: ThreadWorkerGlobalScope, ev: MessageEvents) => void;
954
955  /**
956   * The onmessage attribute of parentPort specifies the event handler
957   * to be called then the worker receives a message that cannot be deserialized.
958   * The event handler is executed in the worker thread.
959   *
960   * @throws { BusinessError } 401 - if the input parameters are invalid.
961   * @throws { BusinessError } 10200004 - Worker instance is not running.
962   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
963   * @syscap SystemCapability.Utils.Lang
964   * @since 9
965   */
966  /**
967   * The onmessage attribute of parentPort specifies the event handler
968   * to be called then the worker receives a message that cannot be deserialized.
969   * The event handler is executed in the worker thread.
970   *
971   * @throws { BusinessError } 401 - if the input parameters are invalid.
972   * @throws { BusinessError } 10200004 - Worker instance is not running.
973   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
974   * @syscap SystemCapability.Utils.Lang
975   * @crossplatform
976   * @since 10
977   */
978  /**
979   * The onmessage attribute of parentPort specifies the event handler
980   * to be called then the worker receives a message that cannot be deserialized.
981   * The event handler is executed in the worker thread.
982   *
983   * @throws { BusinessError } 401 - if the input parameters are invalid.
984   * @throws { BusinessError } 10200004 - Worker instance is not running.
985   * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
986   * @syscap SystemCapability.Utils.Lang
987   * @crossplatform
988   * @atomicservice
989   * @since 11
990   */
991  onmessageerror?: (this: ThreadWorkerGlobalScope, ev: MessageEvents) => void;
992
993  /**
994   * Close the worker thread to stop the worker from receiving messages
995   *
996   * @throws { BusinessError } 10200004 - Worker instance is not running.
997   * @syscap SystemCapability.Utils.Lang
998   * @since 9
999   */
1000  /**
1001   * Close the worker thread to stop the worker from receiving messages
1002   *
1003   * @throws { BusinessError } 10200004 - Worker instance is not running.
1004   * @syscap SystemCapability.Utils.Lang
1005   * @crossplatform
1006   * @since 10
1007   */
1008  /**
1009   * Close the worker thread to stop the worker from receiving messages
1010   *
1011   * @throws { BusinessError } 10200004 - Worker instance is not running.
1012   * @syscap SystemCapability.Utils.Lang
1013   * @crossplatform
1014   * @atomicservice
1015   * @since 11
1016   */
1017  close(): void;
1018
1019  /**
1020   * Send a message to host thread from the worker
1021   *
1022   * @param { Object } messageObject - messageObject Data to be sent to the worker
1023   * @param { ArrayBuffer[] } transfer - transfer array cannot contain null.
1024   * @throws { BusinessError } 401 - if the input parameters are invalid.
1025   * @throws { BusinessError } 10200004 - Worker instance is not running.
1026   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1027   * @syscap SystemCapability.Utils.Lang
1028   * @since 9
1029   */
1030  /**
1031   * Send a message to host thread from the worker
1032   *
1033   * @param { Object } messageObject - messageObject Data to be sent to the worker
1034   * @param { ArrayBuffer[] } transfer - transfer array cannot contain null.
1035   * @throws { BusinessError } 401 - if the input parameters are invalid.
1036   * @throws { BusinessError } 10200004 - Worker instance is not running.
1037   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1038   * @syscap SystemCapability.Utils.Lang
1039   * @crossplatform
1040   * @since 10
1041   */
1042  /**
1043   * Send a message to host thread from the worker
1044   *
1045   * @param { Object } messageObject - messageObject Data to be sent to the worker
1046   * @param { ArrayBuffer[] } transfer - transfer array cannot contain null.
1047   * @throws { BusinessError } 401 - if the input parameters are invalid.
1048   * @throws { BusinessError } 10200004 - Worker instance is not running.
1049   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1050   * @syscap SystemCapability.Utils.Lang
1051   * @crossplatform
1052   * @atomicservice
1053   * @since 11
1054   */
1055  postMessage(messageObject: Object, transfer: ArrayBuffer[]): void;
1056
1057  /**
1058   * Send a message to be host thread from the worker
1059   *
1060   * @param { Object } messageObject - messageObject Data to be sent to the worker
1061   * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
1062   * @throws { BusinessError } 401 - if the input parameters are invalid.
1063   * @throws { BusinessError } 10200004 - Worker instance is not running.
1064   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1065   * @syscap SystemCapability.Utils.Lang
1066   * @since 9
1067   */
1068  /**
1069   * Send a message to be host thread from the worker
1070   *
1071   * @param { Object } messageObject - messageObject Data to be sent to the worker
1072   * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
1073   * @throws { BusinessError } 401 - if the input parameters are invalid.
1074   * @throws { BusinessError } 10200004 - Worker instance is not running.
1075   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1076   * @syscap SystemCapability.Utils.Lang
1077   * @crossplatform
1078   * @since 10
1079   */
1080  /**
1081   * Send a message to be host thread from the worker
1082   *
1083   * @param { Object } messageObject - messageObject Data to be sent to the worker
1084   * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
1085   * @throws { BusinessError } 401 - if the input parameters are invalid.
1086   * @throws { BusinessError } 10200004 - Worker instance is not running.
1087   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1088   * @syscap SystemCapability.Utils.Lang
1089   * @crossplatform
1090   * @atomicservice
1091   * @since 11
1092   */
1093  postMessage(messageObject: Object, options?: PostMessageOptions): void;
1094
1095  /**
1096   * Send a global call on registered globalCallObject on host side and return the result synchronously
1097   *
1098   * @param { string } instanceName - the exact key used in registration
1099   * @param { string } methodName - a string which is same to the method called on globalCallObject.
1100   * @param { number } timeout - the specific milliseconds that will wait for result to return, between 0 and 5000.
1101   * @param { Object[] } args - the method argument called on registered globalCallObject.
1102   * @returns { Object } Return the result of method if it has a return value, otherwise return void.
1103   * @throws { BusinessError } 401 - The input parameters are invalid.
1104   * @throws { BusinessError } 10200004 - Worker instance is not running.
1105   * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1106   * @throws { BusinessError } 10200019 - The globalCallObject is not registered.
1107   * @throws { BusinessError } 10200020 - The method to be called is not callable or is an async method or a generator.
1108   * @throws { BusinessError } 10200021 - The global call exceeds the timeout.
1109   * @syscap SystemCapability.Utils.Lang
1110   * @crossplatform
1111   * @since 11
1112   */
1113  callGlobalCallObjectMethod(instanceName: string, methodName: string, timeout: number, ...args: Object[]): Object;
1114}
1115
1116/**
1117 * JS cross-thread communication tool
1118 *
1119 * @namespace worker
1120 * @syscap SystemCapability.Utils.Lang
1121 * @since 7
1122 */
1123/**
1124 * JS cross-thread communication tool
1125 *
1126 * @namespace worker
1127 * @syscap SystemCapability.Utils.Lang
1128 * @crossplatform
1129 * @since 10
1130 */
1131/**
1132 * JS cross-thread communication tool
1133 *
1134 * @namespace worker
1135 * @syscap SystemCapability.Utils.Lang
1136 * @crossplatform
1137 * @atomicservice
1138 * @since 11
1139 */
1140declare namespace worker {
1141  /**
1142   * The ThreadWorker class contains all Worker functions.
1143   *
1144   * @syscap SystemCapability.Utils.Lang
1145   * @since 9
1146   */
1147  /**
1148   * The ThreadWorker class contains all Worker functions.
1149   *
1150   * @syscap SystemCapability.Utils.Lang
1151   * @crossplatform
1152   * @since 10
1153   */
1154  /**
1155   * The ThreadWorker class contains all Worker functions.
1156   *
1157   * @syscap SystemCapability.Utils.Lang
1158   * @crossplatform
1159   * @atomicservice
1160   * @since 11
1161   */
1162  class ThreadWorker implements WorkerEventTarget {
1163    /**
1164     * Creates a worker instance
1165     *
1166     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
1167     * @param { WorkerOptions } [options] - options Options that can be set for the worker
1168     * @throws { BusinessError } 401 - if the input parameters are invalid.
1169     * @throws { BusinessError } 10200003 - Worker initialization failure.
1170     * @throws { BusinessError } 10200007 - The worker file patch is invalid path.
1171     * @syscap SystemCapability.Utils.Lang
1172     * @since 9
1173     */
1174    /**
1175     * Creates a worker instance
1176     *
1177     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
1178     * @param { WorkerOptions } [options] - options Options that can be set for the worker
1179     * @throws { BusinessError } 401 - if the input parameters are invalid.
1180     * @throws { BusinessError } 10200003 - Worker initialization failure.
1181     * @throws { BusinessError } 10200007 - The worker file patch is invalid path.
1182     * @syscap SystemCapability.Utils.Lang
1183     * @crossplatform
1184     * @since 10
1185     */
1186    /**
1187     * Creates a worker instance
1188     *
1189     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
1190     * @param { WorkerOptions } [options] - options Options that can be set for the worker
1191     * @throws { BusinessError } 401 - if the input parameters are invalid.
1192     * @throws { BusinessError } 10200003 - Worker initialization failure.
1193     * @throws { BusinessError } 10200007 - The worker file patch is invalid path.
1194     * @syscap SystemCapability.Utils.Lang
1195     * @crossplatform
1196     * @atomicservice
1197     * @since 11
1198     */
1199    constructor(scriptURL: string, options?: WorkerOptions);
1200    /**
1201     * The onexit attribute of the worker specifies the event handler to be called
1202     * when the worker exits. The handler is executed in the host thread.
1203     *
1204     * @throws { BusinessError } 401 - if the input parameters are invalid.
1205     * @throws { BusinessError } 10200004 - Worker instance is not running.
1206     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1207     * @syscap SystemCapability.Utils.Lang
1208     * @since 9
1209     */
1210    /**
1211     * The onexit attribute of the worker specifies the event handler to be called
1212     * when the worker exits. The handler is executed in the host thread.
1213     *
1214     * @throws { BusinessError } 401 - if the input parameters are invalid.
1215     * @throws { BusinessError } 10200004 - Worker instance is not running.
1216     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1217     * @syscap SystemCapability.Utils.Lang
1218     * @crossplatform
1219     * @since 10
1220     */
1221    /**
1222     * The onexit attribute of the worker specifies the event handler to be called
1223     * when the worker exits. The handler is executed in the host thread.
1224     *
1225     * @throws { BusinessError } 401 - if the input parameters are invalid.
1226     * @throws { BusinessError } 10200004 - Worker instance is not running.
1227     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1228     * @syscap SystemCapability.Utils.Lang
1229     * @crossplatform
1230     * @atomicservice
1231     * @since 11
1232     */
1233    onexit?: (code: number) => void;
1234    /**
1235     * The onerror attribute of the worker specifies the event handler to be called
1236     * when an exception occurs during worker execution.
1237     * The event handler is executed in the host thread.
1238     *
1239     * @throws { BusinessError } 401 - if the input parameters are invalid.
1240     * @throws { BusinessError } 10200004 - Worker instance is not running.
1241     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1242     * @syscap SystemCapability.Utils.Lang
1243     * @since 9
1244     */
1245    /**
1246     * The onerror attribute of the worker specifies the event handler to be called
1247     * when an exception occurs during worker execution.
1248     * The event handler is executed in the host thread.
1249     *
1250     * @throws { BusinessError } 401 - if the input parameters are invalid.
1251     * @throws { BusinessError } 10200004 - Worker instance is not running.
1252     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1253     * @syscap SystemCapability.Utils.Lang
1254     * @crossplatform
1255     * @since 10
1256     */
1257    /**
1258     * The onerror attribute of the worker specifies the event handler to be called
1259     * when an exception occurs during worker execution.
1260     * The event handler is executed in the host thread.
1261     *
1262     * @throws { BusinessError } 401 - if the input parameters are invalid.
1263     * @throws { BusinessError } 10200004 - Worker instance is not running.
1264     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1265     * @syscap SystemCapability.Utils.Lang
1266     * @crossplatform
1267     * @atomicservice
1268     * @since 11
1269     */
1270    onerror?: (err: ErrorEvent) => void;
1271    /**
1272     * The onmessage attribute of the worker specifies the event handler
1273     * to be called then the host thread receives a message created by itself
1274     * and sent by the worker through the parentPort.postMessage.
1275     * The event handler is executed in the host thread.
1276     *
1277     * @throws { BusinessError } 401 - if the input parameters are invalid.
1278     * @throws { BusinessError } 10200004 - Worker instance is not running.
1279     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1280     * @syscap SystemCapability.Utils.Lang
1281     * @since 9
1282     */
1283    /**
1284     * The onmessage attribute of the worker specifies the event handler
1285     * to be called then the host thread receives a message created by itself
1286     * and sent by the worker through the parentPort.postMessage.
1287     * The event handler is executed in the host thread.
1288     *
1289     * @throws { BusinessError } 401 - if the input parameters are invalid.
1290     * @throws { BusinessError } 10200004 - Worker instance is not running.
1291     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1292     * @syscap SystemCapability.Utils.Lang
1293     * @crossplatform
1294     * @since 10
1295     */
1296    /**
1297     * The onmessage attribute of the worker specifies the event handler
1298     * to be called then the host thread receives a message created by itself
1299     * and sent by the worker through the parentPort.postMessage.
1300     * The event handler is executed in the host thread.
1301     *
1302     * @throws { BusinessError } 401 - if the input parameters are invalid.
1303     * @throws { BusinessError } 10200004 - Worker instance is not running.
1304     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1305     * @syscap SystemCapability.Utils.Lang
1306     * @crossplatform
1307     * @atomicservice
1308     * @since 11
1309     */
1310    onmessage?: (event: MessageEvents) => void;
1311    /**
1312     * The onmessage attribute of the worker specifies the event handler
1313     * when the worker receives a message that cannot be serialized.
1314     * The event handler is executed in the host thread.
1315     *
1316     * @throws { BusinessError } 401 - if the input parameters are invalid.
1317     * @throws { BusinessError } 10200004 - Worker instance is not running.
1318     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1319     * @syscap SystemCapability.Utils.Lang
1320     * @since 9
1321     */
1322    /**
1323     * The onmessage attribute of the worker specifies the event handler
1324     * when the worker receives a message that cannot be serialized.
1325     * The event handler is executed in the host thread.
1326     *
1327     * @throws { BusinessError } 401 - if the input parameters are invalid.
1328     * @throws { BusinessError } 10200004 - Worker instance is not running.
1329     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1330     * @syscap SystemCapability.Utils.Lang
1331     * @crossplatform
1332     * @since 10
1333     */
1334    /**
1335     * The onmessage attribute of the worker specifies the event handler
1336     * when the worker receives a message that cannot be serialized.
1337     * The event handler is executed in the host thread.
1338     *
1339     * @throws { BusinessError } 401 - if the input parameters are invalid.
1340     * @throws { BusinessError } 10200004 - Worker instance is not running.
1341     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1342     * @syscap SystemCapability.Utils.Lang
1343     * @crossplatform
1344     * @atomicservice
1345     * @since 11
1346     */
1347    onmessageerror?: (event: MessageEvents) => void;
1348    /**
1349     * Sends a message to the worker thread.
1350     * The data is transferred using the structured clone algorithm.
1351     *
1352     * @param { Object } message - message Data to be sent to the worker
1353     * @param { ArrayBuffer[] } transfer - transfer ArrayBuffer instance that can be transferred.
1354     * The transferList array cannot contain null.
1355     * @throws { BusinessError } 401 - if the input parameters are invalid.
1356     * @throws { BusinessError } 10200004 - Worker instance is not running.
1357     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1358     * @syscap SystemCapability.Utils.Lang
1359     * @since 9
1360     */
1361    /**
1362     * Sends a message to the worker thread.
1363     * The data is transferred using the structured clone algorithm.
1364     *
1365     * @param { Object } message - message Data to be sent to the worker
1366     * @param { ArrayBuffer[] } transfer - transfer ArrayBuffer instance that can be transferred.
1367     * The transferList array cannot contain null.
1368     * @throws { BusinessError } 401 - if the input parameters are invalid.
1369     * @throws { BusinessError } 10200004 - Worker instance is not running.
1370     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1371     * @syscap SystemCapability.Utils.Lang
1372     * @crossplatform
1373     * @since 10
1374     */
1375    /**
1376     * Sends a message to the worker thread.
1377     * The data is transferred using the structured clone algorithm.
1378     *
1379     * @param { Object } message - message Data to be sent to the worker
1380     * @param { ArrayBuffer[] } transfer - transfer ArrayBuffer instance that can be transferred.
1381     * The transferList array cannot contain null.
1382     * @throws { BusinessError } 401 - if the input parameters are invalid.
1383     * @throws { BusinessError } 10200004 - Worker instance is not running.
1384     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1385     * @syscap SystemCapability.Utils.Lang
1386     * @crossplatform
1387     * @atomicservice
1388     * @since 11
1389     */
1390    postMessage(message: Object, transfer: ArrayBuffer[]): void;
1391    /**
1392     * Sends a message to the worker thread.
1393     * The data is transferred using the structured clone algorithm.
1394     *
1395     * @param { Object } message - message Data to be sent to the worker
1396     * @param { PostMessageOptions } [options] - options
1397     * @throws { BusinessError } 401 - if the input parameters are invalid.
1398     * @throws { BusinessError } 10200004 - Worker instance is not running.
1399     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1400     * @syscap SystemCapability.Utils.Lang
1401     * @since 9
1402     */
1403    /**
1404     * Sends a message to the worker thread.
1405     * The data is transferred using the structured clone algorithm.
1406     *
1407     * @param { Object } message - message Data to be sent to the worker
1408     * @param { PostMessageOptions } [options] - options
1409     * @throws { BusinessError } 401 - if the input parameters are invalid.
1410     * @throws { BusinessError } 10200004 - Worker instance is not running.
1411     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1412     * @syscap SystemCapability.Utils.Lang
1413     * @crossplatform
1414     * @since 10
1415     */
1416    /**
1417     * Sends a message to the worker thread.
1418     * The data is transferred using the structured clone algorithm.
1419     *
1420     * @param { Object } message - message Data to be sent to the worker
1421     * @param { PostMessageOptions } [options] - options
1422     * @throws { BusinessError } 401 - if the input parameters are invalid.
1423     * @throws { BusinessError } 10200004 - Worker instance is not running.
1424     * @throws { BusinessError } 10200006 - An exception occurred during serialization.
1425     * @syscap SystemCapability.Utils.Lang
1426     * @crossplatform
1427     * @atomicservice
1428     * @since 11
1429     */
1430    postMessage(message: Object, options?: PostMessageOptions): void;
1431    /**
1432     * Adds an event listener to the worker.
1433     *
1434     * @param { string } type - type Adds an event listener to the worker.
1435     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
1436     * @throws { BusinessError } 401 - if the input parameters are invalid.
1437     * @throws { BusinessError } 10200004 - Worker instance is not running.
1438     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1439     * @syscap SystemCapability.Utils.Lang
1440     * @since 9
1441     */
1442    /**
1443     * Adds an event listener to the worker.
1444     *
1445     * @param { string } type - type Adds an event listener to the worker.
1446     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs.
1447     * @throws { BusinessError } 401 - if the input parameters are invalid.
1448     * @throws { BusinessError } 10200004 - Worker instance is not running.
1449     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1450     * @syscap SystemCapability.Utils.Lang
1451     * @crossplatform
1452     * @since 10
1453     */
1454    on(type: string, listener: WorkerEventListener): void;
1455    /**
1456     * Adds an event listener to the worker
1457     * and removes the event listener automatically after it is invoked once.
1458     *
1459     * @param { string } type - type Type of the event to listen for
1460     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs
1461     * @throws { BusinessError } 401 - if the input parameters are invalid.
1462     * @throws { BusinessError } 10200004 - Worker instance is not running.
1463     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1464     * @syscap SystemCapability.Utils.Lang
1465     * @since 9
1466     */
1467    /**
1468     * Adds an event listener to the worker
1469     * and removes the event listener automatically after it is invoked once.
1470     *
1471     * @param { string } type - type Type of the event to listen for
1472     * @param { WorkerEventListener } listener - listener Callback to invoke when an event of the specified type occurs
1473     * @throws { BusinessError } 401 - if the input parameters are invalid.
1474     * @throws { BusinessError } 10200004 - Worker instance is not running.
1475     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1476     * @syscap SystemCapability.Utils.Lang
1477     * @crossplatform
1478     * @since 10
1479     */
1480    once(type: string, listener: WorkerEventListener): void;
1481    /**
1482     * Removes an event listener to the worker.
1483     *
1484     * @param { string } type - type Type of the event for which the event listener is removed.
1485     * @param { WorkerEventListener } [listener] - listener Callback of the event listener to remove.
1486     * @throws { BusinessError } 401 - if the input parameters are invalid.
1487     * @throws { BusinessError } 10200004 - Worker instance is not running.
1488     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1489     * @syscap SystemCapability.Utils.Lang
1490     * @since 9
1491     */
1492    /**
1493     * Removes an event listener to the worker.
1494     *
1495     * @param { string } type - type Type of the event for which the event listener is removed.
1496     * @param { WorkerEventListener } [listener] - listener Callback of the event listener to remove.
1497     * @throws { BusinessError } 401 - if the input parameters are invalid.
1498     * @throws { BusinessError } 10200004 - Worker instance is not running.
1499     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1500     * @syscap SystemCapability.Utils.Lang
1501     * @crossplatform
1502     * @since 10
1503     */
1504    off(type: string, listener?: WorkerEventListener): void;
1505    /**
1506     * Terminates the worker thread to stop the worker from receiving messages
1507     *
1508     * @throws { BusinessError } 10200004 - Worker instance is not running.
1509     * @syscap SystemCapability.Utils.Lang
1510     * @since 9
1511     */
1512    /**
1513     * Terminates the worker thread to stop the worker from receiving messages
1514     *
1515     * @throws { BusinessError } 10200004 - Worker instance is not running.
1516     * @syscap SystemCapability.Utils.Lang
1517     * @crossplatform
1518     * @since 10
1519     */
1520    /**
1521     * Terminates the worker thread to stop the worker from receiving messages
1522     *
1523     * @throws { BusinessError } 10200004 - Worker instance is not running.
1524     * @syscap SystemCapability.Utils.Lang
1525     * @crossplatform
1526     * @atomicservice
1527     * @since 11
1528     */
1529    terminate(): void;
1530    /**
1531     * Adds an event listener to the worker.
1532     *
1533     * @param { string } type - type Type of the event to listen for.
1534     * @param { WorkerEventListener } listener Callback to invoke when an event of the specified type occurs.
1535     * @throws { BusinessError } 401 - if the input parameters are invalid.
1536     * @throws { BusinessError } 10200004 - Worker instance is not running.
1537     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1538     * @syscap SystemCapability.Utils.Lang
1539     * @since 9
1540     */
1541    /**
1542     * Adds an event listener to the worker.
1543     *
1544     * @param { string } type - type Type of the event to listen for.
1545     * @param { WorkerEventListener } listener Callback to invoke when an event of the specified type occurs.
1546     * @throws { BusinessError } 401 - if the input parameters are invalid.
1547     * @throws { BusinessError } 10200004 - Worker instance is not running.
1548     * @throws { BusinessError } 10200005 - The invoked API is not supported in workers.
1549     * @syscap SystemCapability.Utils.Lang
1550     * @crossplatform
1551     * @since 10
1552     */
1553    addEventListener(type: string, listener: WorkerEventListener): void;
1554    /**
1555     * Handle the event defined for the worker.
1556     *
1557     * @param { Event } event - event Event to dispatch.
1558     * @returns { boolean }
1559     * @throws { BusinessError } 401 - if the input parameters are invalid.
1560     * @throws { BusinessError } 10200004 - Worker instance is not running.
1561     * @syscap SystemCapability.Utils.Lang
1562     * @since 9
1563     */
1564    /**
1565     * Handle the event defined for the worker.
1566     *
1567     * @param { Event } event - event Event to dispatch.
1568     * @returns { boolean }
1569     * @throws { BusinessError } 401 - if the input parameters are invalid.
1570     * @throws { BusinessError } 10200004 - Worker instance is not running.
1571     * @syscap SystemCapability.Utils.Lang
1572     * @crossplatform
1573     * @since 10
1574     */
1575    dispatchEvent(event: Event): boolean;
1576    /**
1577     * Remove an event defined for the worker.
1578     *
1579     * @param { string } type - type Type of the event for which the event listener is cancelled.
1580     * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
1581     * @throws { BusinessError } 401 - if the input parameters are invalid.
1582     * @throws { BusinessError } 10200004 - Worker instance is not running.
1583     * @syscap SystemCapability.Utils.Lang
1584     * @since 9
1585     */
1586    /**
1587     * Remove an event defined for the worker.
1588     *
1589     * @param { string } type - type Type of the event for which the event listener is cancelled.
1590     * @param { WorkerEventListener } [callback] - callback Callback of the event listener to remove.
1591     * @throws { BusinessError } 401 - if the input parameters are invalid.
1592     * @throws { BusinessError } 10200004 - Worker instance is not running.
1593     * @syscap SystemCapability.Utils.Lang
1594     * @crossplatform
1595     * @since 10
1596     */
1597    removeEventListener(type: string, callback?: WorkerEventListener): void;
1598    /**
1599     * Remove all event listeners for the worker.
1600     *
1601     * @throws { BusinessError } 10200004 - Worker instance is not running.
1602     * @syscap SystemCapability.Utils.Lang
1603     * @since 9
1604     */
1605    /**
1606     * Remove all event listeners for the worker.
1607     *
1608     * @throws { BusinessError } 10200004 - Worker instance is not running.
1609     * @syscap SystemCapability.Utils.Lang
1610     * @crossplatform
1611     * @since 10
1612     */
1613    removeAllListener(): void;
1614
1615    /**
1616     * Register globalCallObject for global call.
1617     * @param { string } instanceName - The key to register globalCallObject.
1618     * @param { Object } globalCallObject - The globalCallObject that will be registered.
1619     * @throws { BusinessError } 401 - The input parameters are invalid.
1620     * @throws { BusinessError } 10200004 - Worker instance is not running.
1621     * @syscap SystemCapability.Utils.Lang
1622     * @crossplatform
1623     * @since 11
1624     */
1625    registerGlobalCallObject(instanceName: string, globalCallObject: Object): void;
1626
1627    /**
1628     * Remove registered globalCallObject and release strong reference to registered object.
1629     * @param { string } [instanceName] - The exact key that used in registration.
1630     * @throws { BusinessError } 401 - The input parameters are invalid.
1631     * @throws { BusinessError } 10200004 - Worker instance is not running.
1632     * @syscap SystemCapability.Utils.Lang
1633     * @crossplatform
1634     * @since 11
1635     */
1636    unregisterGlobalCallObject(instanceName?: string): void;
1637  }
1638
1639  /**
1640   * The RestrictedWorker class contains all Worker functions.
1641   *
1642   * @extends ThreadWorker
1643   * @syscap SystemCapability.Utils.Lang
1644   * @since 11
1645   */
1646  class RestrictedWorker extends ThreadWorker {
1647    /**
1648     * Creates a worker instance
1649     *
1650     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
1651     * @param { WorkerOptions } [options] - options Options that can be set for the worker
1652     * @throws { BusinessError } 401 - if the input parameters are invalid.
1653     * @throws { BusinessError } 10200003 - Worker initialization failure.
1654     * @throws { BusinessError } 10200007 - The worker file patch is invalid path.
1655     * @syscap SystemCapability.Utils.Lang
1656     * @since 11
1657     */
1658    constructor(scriptURL: string, options?: WorkerOptions);
1659  }
1660
1661  /**
1662   * The Worker class contains all Worker functions.
1663   *
1664   * @syscap SystemCapability.Utils.Lang
1665   * @since 7
1666   * @deprecated since 9
1667   * @useinstead ohos.worker.ThreadWorker
1668   */
1669  class Worker implements EventTarget {
1670    /**
1671     * Creates a worker instance
1672     *
1673     * @param { string } scriptURL - scriptURL URL of the script to be executed by the worker
1674     * @param { WorkerOptions } options - options Options that can be set for the worker
1675     * @syscap SystemCapability.Utils.Lang
1676     * @since 7
1677     * @deprecated since 9
1678     * @useinstead ohos.worker.ThreadWorker.constructor
1679     */
1680    constructor(scriptURL: string, options?: WorkerOptions);
1681
1682    /**
1683     * The onexit attribute of the worker specifies the event handler to be called
1684     * when the worker exits. The handler is executed in the host thread.
1685     *
1686     * @syscap SystemCapability.Utils.Lang
1687     * @since 7
1688     * @deprecated since 9
1689     * @useinstead ohos.worker.ThreadWorker.onexit
1690     */
1691    onexit?: (code: number) => void;
1692
1693    /**
1694     * The onerror attribute of the worker specifies the event handler to be called
1695     * when an exception occurs during worker execution.
1696     * The event handler is executed in the host thread.
1697     *
1698     * @syscap SystemCapability.Utils.Lang
1699     * @since 7
1700     * @deprecated since 9
1701     * @useinstead ohos.worker.ThreadWorker.onerror
1702     */
1703    onerror?: (err: ErrorEvent) => void;
1704
1705    /**
1706     * The onmessage attribute of the worker specifies the event handler
1707     * to be called then the host thread receives a message created by itself
1708     * and sent by the worker through the parentPort.postMessage.
1709     * The event handler is executed in the host thread.
1710     *
1711     * @syscap SystemCapability.Utils.Lang
1712     * @since 7
1713     * @deprecated since 9
1714     * @useinstead ohos.worker.ThreadWorker.onmessage
1715     */
1716    onmessage?: (event: MessageEvent) => void;
1717
1718    /**
1719     * The onmessage attribute of the worker specifies the event handler
1720     * when the worker receives a message that cannot be serialized.
1721     * The event handler is executed in the host thread.
1722     *
1723     * @syscap SystemCapability.Utils.Lang
1724     * @since 7
1725     * @deprecated since 9
1726     * @useinstead ohos.worker.ThreadWorker.onmessageerror
1727     */
1728    onmessageerror?: (event: MessageEvent) => void;
1729
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 - 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     * @syscap SystemCapability.Utils.Lang
1738     * @since 7
1739     * @deprecated since 9
1740     * @useinstead ohos.worker.ThreadWorker.postMessage
1741     */
1742    postMessage(message: Object, transfer: ArrayBuffer[]): void;
1743
1744    /**
1745     * Sends a message to the worker thread.
1746     * The data is transferred using the structured clone algorithm.
1747     *
1748     * @param { Object } message - message - message Data to be sent to the worker
1749     * @param { PostMessageOptions } [options] - options Option can be set for postmessage.
1750     * The transferList array cannot contain null.
1751     * @syscap SystemCapability.Utils.Lang
1752     * @since 7
1753     * @deprecated since 9
1754     * @useinstead ohos.worker.ThreadWorker.postMessage
1755     */
1756    postMessage(message: Object, options?: PostMessageOptions): void;
1757
1758    /**
1759     * Adds an event listener to the worker.
1760     *
1761     * @param { string } type - type Adds an event listener to the worker.
1762     * @param { EventListener } listener - listener Callback to invoke when an event of the specified type occurs.
1763     * @syscap SystemCapability.Utils.Lang
1764     * @since 7
1765     * @deprecated since 9
1766     * @useinstead ohos.worker.ThreadWorker.on
1767     */
1768    on(type: string, listener: EventListener): void;
1769
1770    /**
1771     * Adds an event listener to the worker
1772     * and removes the event listener automatically after it is invoked once.
1773     *
1774     * @param { string } type - type Type of the event to listen for
1775     * @param { EventListener } listener - listener Callback to invoke when an event of the specified type occurs
1776     * @syscap SystemCapability.Utils.Lang
1777     * @since 7
1778     * @deprecated since 9
1779     * @useinstead ohos.worker.ThreadWorker.once
1780     */
1781    once(type: string, listener: EventListener): void;
1782
1783    /**
1784     * Removes an event listener to the worker.
1785     *
1786     * @param { string } type - type Type of the event for which the event listener is removed.
1787     * @param { EventListener } listener - listener Callback of the event listener to remove.
1788     * @syscap SystemCapability.Utils.Lang
1789     * @since 7
1790     * @deprecated since 9
1791     * @useinstead ohos.worker.ThreadWorker.off
1792     */
1793    off(type: string, listener?: EventListener): void;
1794
1795    /**
1796     * Terminates the worker thread to stop the worker from receiving messages
1797     *
1798     * @syscap SystemCapability.Utils.Lang
1799     * @since 7
1800     * @deprecated since 9
1801     * @useinstead ohos.worker.ThreadWorker.terminate
1802     */
1803    terminate(): void;
1804  }
1805
1806  /**
1807   * The object used by the worker thread to communicate with the host thread.
1808   *
1809   * @constant
1810   * @syscap SystemCapability.Utils.Lang
1811   * @since 7
1812   * @deprecated since 9
1813   * @useinstead ohos.worker.workerPort
1814   */
1815  const parentPort: DedicatedWorkerGlobalScope;
1816
1817  /**
1818   * The object used by the worker thread to communicate with the host thread.
1819   *
1820   * @constant
1821   * @syscap SystemCapability.Utils.Lang
1822   * @since 9
1823   */
1824  /**
1825   * The object used by the worker thread to communicate with the host thread.
1826   *
1827   * @constant
1828   * @syscap SystemCapability.Utils.Lang
1829   * @crossplatform
1830   * @since 10
1831   */
1832  /**
1833   * The object used by the worker thread to communicate with the host thread.
1834   *
1835   * @constant
1836   * @syscap SystemCapability.Utils.Lang
1837   * @crossplatform
1838   * @atomicservice
1839   * @since 11
1840   */
1841  const workerPort: ThreadWorkerGlobalScope;
1842}
1843export default worker;
1844