1/* 2 * Copyright (c) 2022 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 * JS cross-thread task executor. 23 * 24 * @namespace taskpool 25 * @syscap SystemCapability.Utils.Lang 26 * @since 9 27 */ 28/** 29 * JS cross-thread task executor. 30 * 31 * @namespace taskpool 32 * @syscap SystemCapability.Utils.Lang 33 * @crossplatform 34 * @since 10 35 */ 36/** 37 * JS cross-thread task executor. 38 * 39 * @namespace taskpool 40 * @syscap SystemCapability.Utils.Lang 41 * @crossplatform 42 * @atomicservice 43 * @since 11 44 */ 45declare namespace taskpool { 46 /** 47 * The Priority defines the task priority. 48 * 49 * @enum { number } Priority 50 * @syscap SystemCapability.Utils.Lang 51 * @since 9 52 */ 53 /** 54 * The Priority defines the task priority. 55 * 56 * @enum { number } Priority 57 * @syscap SystemCapability.Utils.Lang 58 * @crossplatform 59 * @since 10 60 */ 61 /** 62 * Enumerates the priorities available for created tasks. 63 * 64 * @enum { number } Priority 65 * @syscap SystemCapability.Utils.Lang 66 * @crossplatform 67 * @atomicservice 68 * @since 11 69 */ 70 enum Priority { 71 /** 72 * set task priority to high. 73 * 74 * @syscap SystemCapability.Utils.Lang 75 * @since 9 76 */ 77 /** 78 * set task priority to high. 79 * 80 * @syscap SystemCapability.Utils.Lang 81 * @crossplatform 82 * @since 10 83 */ 84 /** 85 * The task has a high priority. 86 * 87 * @syscap SystemCapability.Utils.Lang 88 * @crossplatform 89 * @atomicservice 90 * @since 11 91 */ 92 HIGH = 0, 93 94 /** 95 * set task priority to medium. 96 * 97 * @syscap SystemCapability.Utils.Lang 98 * @since 9 99 */ 100 /** 101 * set task priority to medium. 102 * 103 * @syscap SystemCapability.Utils.Lang 104 * @crossplatform 105 * @since 10 106 */ 107 /** 108 * The task has a medium priority. 109 * 110 * @syscap SystemCapability.Utils.Lang 111 * @crossplatform 112 * @atomicservice 113 * @since 11 114 */ 115 MEDIUM = 1, 116 117 /** 118 * set task priority to low. 119 * 120 * @syscap SystemCapability.Utils.Lang 121 * @since 9 122 */ 123 /** 124 * set task priority to low. 125 * 126 * @syscap SystemCapability.Utils.Lang 127 * @crossplatform 128 * @since 10 129 */ 130 /** 131 * The task has a low priority. 132 * 133 * @syscap SystemCapability.Utils.Lang 134 * @crossplatform 135 * @atomicservice 136 * @since 11 137 */ 138 LOW = 2, 139 /** 140 * The task is a background task. 141 * 142 * @syscap SystemCapability.Utils.Lang 143 * @crossplatform 144 * @atomicservice 145 * @since 12 146 */ 147 IDLE = 3 148 } 149 150 /** 151 * Describes a callback function. 152 * 153 * @typedef { function } CallbackFunction 154 * @syscap SystemCapability.Utils.Lang 155 * @crossplatform 156 * @atomicservice 157 * @since 12 158 */ 159 type CallbackFunction = () => void; 160 161 /** 162 * Describes a callback function with an error message. 163 * 164 * @typedef { function } CallbackFunctionWithError 165 * @param { Error } e - Error message. 166 * @syscap SystemCapability.Utils.Lang 167 * @crossplatform 168 * @atomicservice 169 * @since 12 170 */ 171 type CallbackFunctionWithError = (e: Error) => void; 172 173 /** 174 * The Task class provides an interface to create a task. 175 * 176 * @syscap SystemCapability.Utils.Lang 177 * @since 9 178 */ 179 /** 180 * The Task class provides an interface to create a task. 181 * 182 * @syscap SystemCapability.Utils.Lang 183 * @crossplatform 184 * @since 10 185 */ 186 /** 187 * Implements a task. Before calling any APIs in Task, you must use constructor to create a Task instance. 188 * A task can be executed for multiple times, placed in a task group, serial queue, or asynchronous queue for execution, 189 * or added with dependencies for execution. 190 * 191 * @syscap SystemCapability.Utils.Lang 192 * @crossplatform 193 * @atomicservice 194 * @since 11 195 */ 196 class Task { 197 /** 198 * Create a Task instance. 199 * 200 * @param { Function } func - func func Concurrent function to execute in taskpool. 201 * @param { unknown[] } args - args args The concurrent function arguments. 202 * @throws { BusinessError } 401 - The input parameters are invalid. 203 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 204 * @syscap SystemCapability.Utils.Lang 205 * @since 9 206 */ 207 /** 208 * Create a Task instance. 209 * 210 * @param { Function } func - func func Concurrent function to execute in taskpool. 211 * @param { unknown[] } args - args args The concurrent function arguments. 212 * @throws { BusinessError } 401 - The input parameters are invalid. 213 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 214 * @syscap SystemCapability.Utils.Lang 215 * @crossplatform 216 * @since 10 217 */ 218 /** 219 * A constructor used to create a Task instance. 220 * 221 * @param { Function } func - Function to be executed. The function must be decorated using @Concurrent. 222 * For details about the supported return value types of the function, see Sequenceable Data Types. 223 * @param { Object[] } args - Arguments of the function. For details about the supported parameter types, 224 * see Sequenceable Data Types. The default value is undefined. 225 * @throws { BusinessError } 401 - The input parameters are invalid. 226 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 227 * @syscap SystemCapability.Utils.Lang 228 * @crossplatform 229 * @atomicservice 230 * @since 11 231 */ 232 constructor(func: Function, ...args: Object[]); 233 234 /** 235 * A constructor used to create a Task instance, with the task name specified. 236 * 237 * @param { string } name - Task name. 238 * @param { Function } func - Function to be executed. The function must be decorated using @Concurrent. 239 * For details about the supported return value types of the function, see Sequenceable Data Types. 240 * @param { Object[] } args - Arguments of the function. For details about the supported parameter types, 241 * see Sequenceable Data Types. The default value is undefined. 242 * @throws { BusinessError } 401 - The input parameters are invalid. 243 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 244 * @syscap SystemCapability.Utils.Lang 245 * @crossplatform 246 * @atomicservice 247 * @since 11 248 */ 249 constructor(name: string, func: Function, ...args: Object[]); 250 251 /** 252 * Check current running Task is canceled or not. 253 * 254 * @returns { boolean } Returns {@code true} if current running task is canceled; returns {@code false} otherwise. 255 * @static 256 * @syscap SystemCapability.Utils.Lang 257 * @crossplatform 258 * @since 10 259 */ 260 /** 261 * Checks whether the running task is canceled. Before using this API, you must create a Task instance. 262 * isCanceled must be used together with taskpool.cancel. If cancel is not called, isCanceled returns false by default. 263 * 264 * @returns { boolean } Returns {@code true} if current running task is canceled; returns {@code false} otherwise. 265 * @static 266 * @syscap SystemCapability.Utils.Lang 267 * @crossplatform 268 * @atomicservice 269 * @since 11 270 */ 271 static isCanceled(): boolean; 272 273 /** 274 * Sends data to the host thread and triggers the registered callback. Before using this API, you must create a Task instance. 275 * NOTE: 276 * 1.The API is called in the TaskPool thread. 277 * 2.Do not use this API in a callback function. 278 * 3.Before calling this API, ensure that the callback function for processing data has been registered in the host thread. 279 * 280 * @param { Object[] } args - Data to be used as the input parameter of the registered callback. For details about 281 * the supported parameter types, see Sequenceable Data Types. The default value is undefined. 282 * @throws { BusinessError } 401 - The input parameters are invalid. 283 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 284 * @throws { BusinessError } 10200022 - The function is not called in the TaskPool thread. 285 * @throws { BusinessError } 10200023 - The function is not called in the concurrent function. 286 * @throws { BusinessError } 10200024 - The callback is not registered on the host side. 287 * @static 288 * @syscap SystemCapability.Utils.Lang 289 * @crossplatform 290 * @atomicservice 291 * @since 11 292 */ 293 static sendData(...args: Object[]): void; 294 295 /** 296 * Set transfer list for this task. 297 * 298 * @param { ArrayBuffer[] } [transfer] - transfer Transfer list of this task, empty array is default. 299 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 300 * @syscap SystemCapability.Utils.Lang 301 * @crossplatform 302 * @since 10 303 */ 304 /** 305 * Sets the task transfer list. Before using this API, you must create a Task instance. If this API is not called, 306 * the ArrayBuffer in the data is transferred by default. 307 * NOTE: 308 * This API is used to set the task transfer list in the form of ArrayBuffer in the task pool. 309 * The ArrayBuffer instance does not copy the content in the task to the worker thread during transfer. 310 * Instead, it transfers the buffer control right to the worker thread. After the transfer, the ArrayBuffer instance 311 * becomes invalid. An empty ArrayBuffer will not be transferred. 312 * 313 * @param { ArrayBuffer[] } [transfer] - ArrayBuffer instance holding the objects to transfer. The default value is an empty array. 314 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 315 * @throws { BusinessError } 10200029 - An ArrayBuffer cannot be set as both a transfer list and a clone list. 316 * @syscap SystemCapability.Utils.Lang 317 * @crossplatform 318 * @atomicservice 319 * @since 11 320 */ 321 setTransferList(transfer?: ArrayBuffer[]): void; 322 323 /** 324 * Sets the task clone list. Before using this API, you must create a Task instance. 325 * NOTE: 326 * This API must be used together with the @Sendable decorator. Otherwise, an exception is thrown. 327 * 328 * @param { Object[] | ArrayBuffer[] } cloneList - The type of the passed-in array must be sendable data types or ArrayBuffer. 329 * All Sendable class instances or ArrayBuffer objects passed in to cloneList are transferred in copy mode between threads. 330 * This means that any modification to the destination objects does not affect the original objects. 331 * @throws { BusinessError } 401 - Parameter error. Possible causes: 332 * 1.Mandatory parameters are left unspecified; 333 * 2.Incorrect parameter types; 334 * 3.Parameter verification failed. 335 * @throws { BusinessError } 10200029 - An ArrayBuffer cannot be set as both a transfer list and a clone list. 336 * @syscap SystemCapability.Utils.Lang 337 * @crossplatform 338 * @atomicservice 339 * @since 11 340 */ 341 setCloneList(cloneList: Object[] | ArrayBuffer[]): void; 342 343 /** 344 * Registers a callback for a task to receive and process data from the worker thread. Before using this API, you must create a Task instance. 345 * NOTE: 346 * If multiple callbacks are registered for the same task, only the last registration takes effect. 347 * 348 * @param { Function } [callback] - Callback function for processing the data received. The data sent to the host 349 * thread is transferred to the callback as an input parameter. If no value is passed in, all the registered callbacks are canceled. 350 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 351 * @syscap SystemCapability.Utils.Lang 352 * @crossplatform 353 * @atomicservice 354 * @since 11 355 */ 356 onReceiveData(callback?: Function): void; 357 358 /** 359 * Add dependencies on the task array for this task. 360 * 361 * @param { Task[] } tasks - tasks tasks An array of dependent tasks. 362 * @throws { BusinessError } 401 - Parameter error. Possible causes: 363 * 1.Mandatory parameters are left unspecified; 364 * 2.Incorrect parameter types; 365 * 3.Parameter verification failed. 366 * @throws { BusinessError } 10200026 - There is a circular dependency. 367 * @syscap SystemCapability.Utils.Lang 368 * @crossplatform 369 * @atomicservice 370 * @since 11 371 */ 372 /** 373 * Add dependencies on the task array for this task. 374 * 375 * @param { Task[] } tasks - An array of dependent tasks. 376 * @throws { BusinessError } 401 - Parameter error. Possible causes: 377 * <br>1. Mandatory parameters are left unspecified; 378 * <br>2. Incorrect parameter types; 379 * <br>3. Parameter verification failed. 380 * @throws { BusinessError } 10200026 - There is a circular dependency. 381 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 382 * @syscap SystemCapability.Utils.Lang 383 * @crossplatform 384 * @atomicservice 385 * @since 12 386 */ 387 /** 388 * Adds dependent tasks for this task. Before using this API, you must create a Task instance. 389 * The task and its dependent tasks cannot be a task in a task group, serial queue, or asynchronous queue, 390 * a task that has been executed, or a periodic task. A task with a dependency relationship (a task that depends 391 * on another task or a task that is depended on) cannot be executed multiple times. 392 * 393 * @param { Task[] } tasks - Array of tasks on which the current task depends. The default value is undefined. 394 * @throws { BusinessError } 401 - Parameter error. Possible causes: 395 * <br>1. Mandatory parameters are left unspecified; 396 * <br>2. Incorrect parameter types; 397 * <br>3. Parameter verification failed. 398 * @throws { BusinessError } 10200026 - There is a circular dependency. 399 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 400 * @throws { BusinessError } 10200056 - The task has been executed by the AsyncRunner. 401 * @syscap SystemCapability.Utils.Lang 402 * @crossplatform 403 * @atomicservice 404 * @since 18 405 */ 406 addDependency(...tasks: Task[]): void; 407 408 /** 409 * Remove dependencies on the task array for this task. 410 * 411 * @param { Task[] } tasks - tasks tasks An array of dependent tasks. 412 * @throws { BusinessError } 401 - Parameter error. Possible causes: 413 * 1.Mandatory parameters are left unspecified; 414 * 2.Incorrect parameter types; 415 * 3.Parameter verification failed. 416 * @throws { BusinessError } 10200027 - The dependency does not exist. 417 * @syscap SystemCapability.Utils.Lang 418 * @crossplatform 419 * @atomicservice 420 * @since 11 421 */ 422 /** 423 * Remove dependencies on the task array for this task. 424 * 425 * @param { Task[] } tasks - An array of dependent tasks. 426 * @throws { BusinessError } 401 - Parameter error. Possible causes: 427 * <br>1. Mandatory parameters are left unspecified; 428 * <br>2. Incorrect parameter types; 429 * <br>3. Parameter verification failed. 430 * @throws { BusinessError } 10200027 - The dependency does not exist. 431 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 432 * @syscap SystemCapability.Utils.Lang 433 * @crossplatform 434 * @atomicservice 435 * @since 12 436 */ 437 /** 438 * Removes dependent tasks for this task. Before using this API, you must create a Task instance. 439 * 440 * @param { Task[] } tasks - Array of tasks on which the current task depends. The default value is undefined. 441 * @throws { BusinessError } 401 - Parameter error. Possible causes: 442 * <br>1. Mandatory parameters are left unspecified; 443 * <br>2. Incorrect parameter types; 444 * <br>3. Parameter verification failed. 445 * @throws { BusinessError } 10200027 - The dependency does not exist. 446 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 447 * @throws { BusinessError } 10200056 - The task has been executed by the AsyncRunner. 448 * @syscap SystemCapability.Utils.Lang 449 * @crossplatform 450 * @atomicservice 451 * @since 18 452 */ 453 removeDependency(...tasks: Task[]): void; 454 455 /** 456 * Register a callback function and call it when a task is enqueued. 457 * The registration must be carried out before the task is executed. Otherwise, an exception is thrown. 458 * 459 * @param { CallbackFunction } [callback] - Callback function to register. 460 * @throws { BusinessError } 401 - The input parameters are invalid. 461 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 462 * @syscap SystemCapability.Utils.Lang 463 * @crossplatform 464 * @atomicservice 465 * @since 12 466 */ 467 onEnqueued(callback: CallbackFunction): void; 468 469 /** 470 * Register a callback function and call it when the execution of a task starts. 471 * The registration must be carried out before the task is executed. Otherwise, an exception is thrown. 472 * 473 * @param { CallbackFunction } [callback] - Callback function to register. 474 * @throws { BusinessError } 401 - The input parameters are invalid. 475 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 476 * @syscap SystemCapability.Utils.Lang 477 * @crossplatform 478 * @atomicservice 479 * @since 12 480 */ 481 onStartExecution(callback: CallbackFunction): void; 482 483 /** 484 * Register a callback function and call it when a task fails to be executed. 485 * The registration must be carried out before the task is executed. Otherwise, an exception is thrown. 486 * 487 * @param { CallbackFunctionWithError } [callback] - Callback function to register. 488 * @throws { BusinessError } 401 - The input parameters are invalid. 489 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 490 * @syscap SystemCapability.Utils.Lang 491 * @crossplatform 492 * @atomicservice 493 * @since 12 494 */ 495 onExecutionFailed(callback: CallbackFunctionWithError): void; 496 497 /** 498 * Register a callback function and call it when a task is executed successfully. 499 * The registration must be carried out before the task is executed. Otherwise, an exception is thrown. 500 * 501 * @param { CallbackFunction } [callback] - Callback function to register. 502 * @throws { BusinessError } 401 - The input parameters are invalid. 503 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 504 * @syscap SystemCapability.Utils.Lang 505 * @crossplatform 506 * @atomicservice 507 * @since 12 508 */ 509 onExecutionSucceeded(callback: CallbackFunction): void; 510 511 /** 512 * Checks whether the task is complete. 513 * 514 * @returns { boolean } Returns {@code true} if the task has been completed; returns {@code false} otherwise. 515 * @syscap SystemCapability.Utils.Lang 516 * @crossplatform 517 * @atomicservice 518 * @since 12 519 */ 520 isDone(): boolean; 521 522 /** 523 * Concurrent function to execute in taskpool. 524 * 525 * @type { Function } 526 * @syscap SystemCapability.Utils.Lang 527 * @since 9 528 */ 529 /** 530 * Concurrent function to execute in taskpool. 531 * 532 * @type { Function } 533 * @syscap SystemCapability.Utils.Lang 534 * @crossplatform 535 * @since 10 536 */ 537 /** 538 * Function to be passed in during task creation. For details about the supported return value types of the function, see Sequenceable Data Types. 539 * 540 * @type { Function } 541 * @syscap SystemCapability.Utils.Lang 542 * @crossplatform 543 * @atomicservice 544 * @since 11 545 */ 546 function: Function; 547 548 /** 549 * The concurrent function arguments. 550 * 551 * @syscap SystemCapability.Utils.Lang 552 * @since 9 553 */ 554 /** 555 * The concurrent function arguments. 556 * 557 * @type { ?unknown[] } 558 * @syscap SystemCapability.Utils.Lang 559 * @crossplatform 560 * @since 10 561 */ 562 /** 563 * Arguments of the function. For details about the supported parameter types, see Sequenceable Data Types. 564 * 565 * @type { ?Object[] } 566 * @syscap SystemCapability.Utils.Lang 567 * @crossplatform 568 * @atomicservice 569 * @since 11 570 */ 571 arguments?: Object[]; 572 573 /** 574 * Name of the task specified when the task is created. 575 * 576 * @type { string } 577 * @syscap SystemCapability.Utils.Lang 578 * @crossplatform 579 * @atomicservice 580 * @since 11 581 */ 582 name: string; 583 584 /** 585 * Task ID. 586 * 587 * @type { number } 588 * @default 0 589 * @syscap SystemCapability.Utils.Lang 590 * @atomicservice 591 * @since 18 592 */ 593 taskId: number; 594 595 /** 596 * Total execution time of the task. in ms. 597 * 598 * @type { number } 599 * @default 0 600 * @syscap SystemCapability.Utils.Lang 601 * @crossplatform 602 * @atomicservice 603 * @since 11 604 */ 605 totalDuration: number; 606 607 /** 608 * Asynchronous I/O time of the task. in ms. 609 * 610 * @type { number } 611 * @default 0 612 * @syscap SystemCapability.Utils.Lang 613 * @crossplatform 614 * @atomicservice 615 * @since 11 616 */ 617 ioDuration: number; 618 619 /** 620 * CPU time of the task. in ms. 621 * 622 * @type { number } 623 * @default 0 624 * @syscap SystemCapability.Utils.Lang 625 * @crossplatform 626 * @atomicservice 627 * @since 11 628 */ 629 cpuDuration: number; 630 } 631 632 /** 633 * The TaskGroup class provides an interface to create a task group. 634 * 635 * @syscap SystemCapability.Utils.Lang 636 * @crossplatform 637 * @since 10 638 */ 639 /** 640 * Implements a task group, in which tasks are associated with each other and all tasks are executed at a time. 641 * If all the tasks are executed normally, an array of task results is returned asynchronously, and the sequence of 642 * elements in the array is the same as the sequence of tasks added by calling addTask. If any task fails, 643 * the corresponding exception is thrown. If multiple tasks in the task group fail, the exception of the first failed 644 * task is thrown. A task group can be executed for multiple times, but no task can be added after the task group is executed. 645 * Before calling any APIs in TaskGroup, you must use constructor to create a TaskGroup instance. 646 * 647 * @syscap SystemCapability.Utils.Lang 648 * @crossplatform 649 * @atomicservice 650 * @since 11 651 */ 652 class TaskGroup { 653 /** 654 * Create a TaskGroup instance. 655 * 656 * @syscap SystemCapability.Utils.Lang 657 * @crossplatform 658 * @since 10 659 */ 660 /** 661 * Constructor used to create a TaskGroup instance. 662 * 663 * @syscap SystemCapability.Utils.Lang 664 * @crossplatform 665 * @atomicservice 666 * @since 11 667 */ 668 constructor(); 669 670 /** 671 * A constructor used to create a TaskGroup instance, with the task group name specified. 672 * 673 * @param { string } name - Task group name. 674 * @throws { BusinessError } 401 - Parameter error. Possible causes: 675 * 1.Mandatory parameters are left unspecified; 676 * 2.Incorrect parameter types; 677 * 3.Parameter verification failed. 678 * @syscap SystemCapability.Utils.Lang 679 * @crossplatform 680 * @atomicservice 681 * @since 11 682 */ 683 constructor(name: string); 684 685 /** 686 * Add a Concurrent function into task group. 687 * 688 * @param { Function } func - func func Concurrent function to add in task group. 689 * @param { unknown[] } args - args args The concurrent function arguments. 690 * @throws { BusinessError } 401 - Parameter error. Possible causes: 691 * 1.Mandatory parameters are left unspecified; 692 * 2.Incorrect parameter types; 693 * 3.Parameter verification failed. 694 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 695 * @syscap SystemCapability.Utils.Lang 696 * @crossplatform 697 * @since 10 698 */ 699 /** 700 * Adds the function to be executed to this task group. Before using this API, you must create a TaskGroup instance. 701 * 702 * @param { Function } func - Function to be executed. The function must be decorated using @Concurrent. 703 * For details about the supported return value types of the function, see Sequenceable Data Types. 704 * @param { Object[] } args - Arguments of the function. For details about the supported parameter types, 705 * see Sequenceable Data Types. The default value is undefined. 706 * @throws { BusinessError } 401 - Parameter error. Possible causes: 707 * 1.Mandatory parameters are left unspecified; 708 * 2.Incorrect parameter types; 709 * 3.Parameter verification failed. 710 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 711 * @syscap SystemCapability.Utils.Lang 712 * @crossplatform 713 * @atomicservice 714 * @since 11 715 */ 716 addTask(func: Function, ...args: Object[]): void; 717 718 /** 719 * Add a Task into TaskGroup. 720 * 721 * @param { Task } task - task task The task want to add in task group. 722 * @throws { BusinessError } 401 - Parameter error. Possible causes: 723 * 1.Mandatory parameters are left unspecified; 724 * 2.Incorrect parameter types; 725 * 3.Parameter verification failed. 726 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 727 * @syscap SystemCapability.Utils.Lang 728 * @crossplatform 729 * @since 10 730 */ 731 /** 732 * Add a Task into TaskGroup. 733 * 734 * @param { Task } task - task task The task want to add in task group. 735 * @throws { BusinessError } 401 - Parameter error. Possible causes: 736 * 1.Mandatory parameters are left unspecified; 737 * 2.Incorrect parameter types; 738 * 3.Parameter verification failed. 739 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 740 * @syscap SystemCapability.Utils.Lang 741 * @crossplatform 742 * @atomicservice 743 * @since 11 744 */ 745 /** 746 * Add a Task into TaskGroup. 747 * 748 * @param { Task } task - The task want to add in task group. 749 * @throws { BusinessError } 401 - Parameter error. Possible causes: 750 * <br>1. Mandatory parameters are left unspecified; 751 * <br>2. Incorrect parameter types; 752 * <br>3. Parameter verification failed. 753 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 754 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 755 * @syscap SystemCapability.Utils.Lang 756 * @crossplatform 757 * @atomicservice 758 * @since 12 759 */ 760 /** 761 * Adds a created task to this task group. Before using this API, you must create a TaskGroup instance. 762 * Tasks in another task group, serial queue, or asynchronous queue, dependent tasks, continuous tasks, 763 * tasks that have been executed, and periodic tasks cannot be added to the task group. 764 * 765 * @param { Task } task - Task to be added to the task group. 766 * @throws { BusinessError } 401 - Parameter error. Possible causes: 767 * <br>1. Mandatory parameters are left unspecified; 768 * <br>2. Incorrect parameter types; 769 * <br>3. Parameter verification failed. 770 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 771 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 772 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 773 * @syscap SystemCapability.Utils.Lang 774 * @crossplatform 775 * @atomicservice 776 * @since 18 777 */ 778 addTask(task: Task): void; 779 780 /** 781 * Name of the task group specified when the task group is created. 782 * 783 * @type { string } 784 * @syscap SystemCapability.Utils.Lang 785 * @crossplatform 786 * @atomicservice 787 * @since 11 788 */ 789 name: string; 790 } 791 792 /** 793 * Implements a serial queue, in which all tasks are executed in sequence. Before calling any APIs in SequenceRunner, 794 * you must use constructor to create a SequenceRunner instance. 795 * 796 * @syscap SystemCapability.Utils.Lang 797 * @crossplatform 798 * @atomicservice 799 * @since 11 800 */ 801 class SequenceRunner { 802 /** 803 * A constructor used to create a SequenceRunner instance. 804 * 805 * @param { Priority } priority - Priority of the task. The default value is taskpool.Priority.MEDIUM. 806 * @throws { BusinessError } 401 - Parameter error. Possible causes: 807 * 1.Incorrect parameter types; 808 * 2.Parameter verification failed. 809 * @syscap SystemCapability.Utils.Lang 810 * @crossplatform 811 * @atomicservice 812 * @since 11 813 */ 814 constructor(priority?: Priority); 815 816 /** 817 * A constructor used to create a SequenceRunner instance. This instance represents a global serial queue. 818 * If the passed-in name is the same as an existing name, the same serial queue is returned. 819 * NOTE: 820 * 1.The bottom layer uses the singleton mode to ensure that the same instance is obtained when a serial queue with the same name is created. 821 * 2.The priority of a serial queue cannot be modified. 822 * 823 * @param { string } name - Name of a serial queue. 824 * @param { Priority } priority - Priority of the task. The default value is taskpool.Priority.MEDIUM. 825 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 826 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 827 * @syscap SystemCapability.Utils.Lang 828 * @crossplatform 829 * @atomicservice 830 * @since 12 831 */ 832 constructor(name: string, priority?: Priority); 833 834 /** 835 * Execute a concurrent function. 836 * 837 * @param { Task } task - The task want to execute. 838 * @returns { Promise<Object> } 839 * @throws { BusinessError } 401 - Parameter error. Possible causes: 840 * 1.Mandatory parameters are left unspecified; 841 * 2.Incorrect parameter types; 842 * @throws { BusinessError } 10200003 - Worker initialization failed. 843 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 844 * @throws { BusinessError } 10200025 - The task to be added to SequenceRunner has dependent tasks. 845 * @syscap SystemCapability.Utils.Lang 846 * @crossplatform 847 * @atomicservice 848 * @since 11 849 */ 850 /** 851 * Execute a concurrent function. 852 * 853 * @param { Task } task - The task want to execute. 854 * @returns { Promise<Object> } 855 * @throws { BusinessError } 401 - Parameter error. Possible causes: 856 * <br>1. Mandatory parameters are left unspecified; 857 * <br>2. Incorrect parameter types; 858 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 859 * @throws { BusinessError } 10200025 - dependent task not allowed. 860 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 861 * @syscap SystemCapability.Utils.Lang 862 * @crossplatform 863 * @atomicservice 864 * @since 12 865 */ 866 /** 867 * Adds a task to the serial queue for execution. Before using this API, you must create a SequenceRunner instance. 868 * Tasks in another task group, serial queue, or asynchronous queue, dependent tasks, and tasks that have been executed cannot be added to the serial queue. 869 * NOTE: 870 * 1.Tasks that depend others cannot be added to the serial queue. 871 * 2.The failure or cancellation of a task does not affect the execution of subsequent tasks in the serial queue. 872 * 873 * @param { Task } task - Task to be added to the serial queue. 874 * @returns { Promise<Object> } 875 * @throws { BusinessError } 401 - Parameter error. Possible causes: 876 * <br>1. Mandatory parameters are left unspecified; 877 * <br>2. Incorrect parameter types; 878 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 879 * @throws { BusinessError } 10200025 - dependent task not allowed. 880 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 881 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 882 * @syscap SystemCapability.Utils.Lang 883 * @crossplatform 884 * @atomicservice 885 * @since 18 886 */ 887 execute(task: Task): Promise<Object>; 888 } 889 890 /** 891 * Describes a continuous task. LongTask inherits from Task. No upper limit is set for the execution time of a continuous task, 892 * and no timeout exception is thrown if a continuous task runs for a long period of time. However, a continuous task cannot be 893 * executed in a task group or executed for multiple times. The thread for executing a continuous task exists until terminateTask 894 * is called after the execution is complete. The thread is reclaimed when it is idle. 895 * 896 * @extends Task 897 * @syscap SystemCapability.Utils.Lang 898 * @crossplatform 899 * @atomicservice 900 * @since 12 901 */ 902 class LongTask extends Task { 903 } 904 905 /** 906 * The GenericsTask class provides an interface to create a task with generics. 907 * 908 * @extends Task 909 * @syscap SystemCapability.Utils.Lang 910 * @atomicservice 911 * @since 13 912 */ 913 /** 914 * Implements a generic task. GenericsTask inherits from Task. During the creation of a generic task, the passed-in 915 * parameter types and return value types of concurrent functions are verified in the compilation phase. 916 * Other behaviors are the same as those during the creation of a task. 917 * 918 * @extends Task 919 * @syscap SystemCapability.Utils.Lang 920 * @crossplatform 921 * @atomicservice 922 * @since 18 923 */ 924 class GenericsTask<A extends Array<Object>, R> extends Task { 925 /** 926 * Create a GenericsTask instance. 927 * 928 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 929 * @param { A } args - The concurrent function arguments. 930 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 931 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 932 * @syscap SystemCapability.Utils.Lang 933 * @atomicservice 934 * @since 13 935 */ 936 /** 937 * A constructor used to create a GenericsTask object. 938 * 939 * @param { (...args: A) => R | Promise<R> } func - Function to be executed. The function must be decorated using @Concurrent. 940 * For details about the supported return value types of the function, see Sequenceable Data Types. 941 * @param { A } args - Arguments of the function. For details about the supported parameter types, see Sequenceable Data Types. 942 * The default value is undefined. 943 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 944 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 945 * @syscap SystemCapability.Utils.Lang 946 * @crossplatform 947 * @atomicservice 948 * @since 18 949 */ 950 constructor(func: (...args: A) => R | Promise<R>, ...args: A); 951 952 /** 953 * Create a GenericsTask instance. 954 * 955 * @param { string } name - The name of GenericsTask. 956 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 957 * @param { A } args - The concurrent function arguments. 958 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 959 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 960 * @syscap SystemCapability.Utils.Lang 961 * @atomicservice 962 * @since 13 963 */ 964 /** 965 * A constructor used to create a GenericsTask instance, with the task name specified. 966 * 967 * @param { string } name - Name of the generic task. 968 * @param { (...args: A) => R | Promise<R> } func - Function to be executed. The function must be decorated using @Concurrent. 969 * For details about the supported return value types of the function, see Sequenceable Data Types. 970 * @param { A } args - Arguments of the function. For details about the supported parameter types, see Sequenceable Data Types. 971 * The default value is undefined. 972 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 973 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 974 * @syscap SystemCapability.Utils.Lang 975 * @crossplatform 976 * @atomicservice 977 * @since 18 978 */ 979 constructor(name: string, func: (...args: A) => R | Promise<R>, ...args: A); 980 } 981 982 /** 983 * The State defines the task state. 984 * 985 * @enum { number } State 986 * @syscap SystemCapability.Utils.Lang 987 * @crossplatform 988 * @since 10 989 */ 990 /** 991 * Enumerates the task states. After a task is created and execute() is called, the task is placed in the internal 992 * queue of the task pool and the state is WAITING. When the task is being executed by the worker thread of the task pool, 993 * the state changes to RUNNING. After the task is executed and the result is returned, the state is reset to WAITING. 994 * When the task is proactively canceled, the state changes to CANCELED. 995 * 996 * @enum { number } State 997 * @syscap SystemCapability.Utils.Lang 998 * @crossplatform 999 * @atomicservice 1000 * @since 11 1001 */ 1002 enum State { 1003 /** 1004 * the task state is waiting. 1005 * 1006 * @syscap SystemCapability.Utils.Lang 1007 * @crossplatform 1008 * @since 10 1009 */ 1010 /** 1011 * The task is waiting. 1012 * 1013 * @syscap SystemCapability.Utils.Lang 1014 * @crossplatform 1015 * @atomicservice 1016 * @since 11 1017 */ 1018 WAITING = 1, 1019 1020 /** 1021 * the task state is running. 1022 * 1023 * @syscap SystemCapability.Utils.Lang 1024 * @crossplatform 1025 * @since 10 1026 */ 1027 /** 1028 * The task is running. 1029 * 1030 * @syscap SystemCapability.Utils.Lang 1031 * @crossplatform 1032 * @atomicservice 1033 * @since 11 1034 */ 1035 RUNNING = 2, 1036 1037 /** 1038 * the task state is canceled. 1039 * 1040 * @syscap SystemCapability.Utils.Lang 1041 * @crossplatform 1042 * @since 10 1043 */ 1044 /** 1045 * The task is canceled. 1046 * 1047 * @syscap SystemCapability.Utils.Lang 1048 * @crossplatform 1049 * @atomicservice 1050 * @since 11 1051 */ 1052 CANCELED = 3 1053 } 1054 1055 /** 1056 * Indicates the internal information of the worker thread. 1057 * 1058 * @syscap SystemCapability.Utils.Lang 1059 * @crossplatform 1060 * @since 10 1061 */ 1062 /** 1063 * Describes the internal information about a task. 1064 * 1065 * @syscap SystemCapability.Utils.Lang 1066 * @crossplatform 1067 * @atomicservice 1068 * @since 11 1069 */ 1070 class TaskInfo { 1071 /** 1072 * Task identity. 1073 * 1074 * @type { number } 1075 * @default 0 1076 * @syscap SystemCapability.Utils.Lang 1077 * @crossplatform 1078 * @since 10 1079 */ 1080 /** 1081 * Task ID. 1082 * 1083 * @type { number } 1084 * @default 0 1085 * @syscap SystemCapability.Utils.Lang 1086 * @crossplatform 1087 * @atomicservice 1088 * @since 11 1089 */ 1090 taskId: number; 1091 1092 /** 1093 * Task state. 1094 * 1095 * @type { State } 1096 * @default State::WAITING 1097 * @syscap SystemCapability.Utils.Lang 1098 * @crossplatform 1099 * @since 10 1100 */ 1101 /** 1102 * Task state. 1103 * 1104 * @type { State } 1105 * @default State::WAITING 1106 * @syscap SystemCapability.Utils.Lang 1107 * @crossplatform 1108 * @atomicservice 1109 * @since 11 1110 */ 1111 state: State; 1112 1113 /** 1114 * Duration of task execution. 1115 * 1116 * @type { ?number } 1117 * @syscap SystemCapability.Utils.Lang 1118 * @crossplatform 1119 * @since 10 1120 */ 1121 /** 1122 * Duration that the task has been executed, in ms. If the return value is 0, the task is not running. If the return value is empty, no task is running. 1123 * 1124 * @type { ?number } 1125 * @syscap SystemCapability.Utils.Lang 1126 * @crossplatform 1127 * @atomicservice 1128 * @since 11 1129 */ 1130 duration?: number; 1131 1132 /** 1133 * Task name. 1134 * 1135 * @type { string } 1136 * @syscap SystemCapability.Utils.Lang 1137 * @crossplatform 1138 * @atomicservice 1139 * @since 12 1140 */ 1141 name: string; 1142 } 1143 1144 /** 1145 * Indicates the internal information of the worker thread. 1146 * 1147 * @syscap SystemCapability.Utils.Lang 1148 * @crossplatform 1149 * @since 10 1150 */ 1151 /** 1152 * Describes the internal information about a worker thread. 1153 * 1154 * @syscap SystemCapability.Utils.Lang 1155 * @crossplatform 1156 * @atomicservice 1157 * @since 11 1158 */ 1159 class ThreadInfo { 1160 /** 1161 * Thread id. 1162 * 1163 * @type { number } 1164 * @default 0 1165 * @syscap SystemCapability.Utils.Lang 1166 * @crossplatform 1167 * @since 10 1168 */ 1169 /** 1170 * ID of the worker thread. If the return value is empty, no task is running. 1171 * 1172 * @type { number } 1173 * @default 0 1174 * @syscap SystemCapability.Utils.Lang 1175 * @crossplatform 1176 * @atomicservice 1177 * @since 11 1178 */ 1179 tid: number; 1180 1181 /** 1182 * Task id list that running on current thread. 1183 * 1184 * @type { ?number[] } 1185 * @syscap SystemCapability.Utils.Lang 1186 * @crossplatform 1187 * @since 10 1188 */ 1189 /** 1190 * IDs of tasks running on the calling thread. If the return value is empty, no task is running. 1191 * 1192 * @type { ?number[] } 1193 * @syscap SystemCapability.Utils.Lang 1194 * @crossplatform 1195 * @atomicservice 1196 * @since 11 1197 */ 1198 taskIds?: number[]; 1199 1200 /** 1201 * Thread priority. 1202 * 1203 * @type { ?Priority } 1204 * @syscap SystemCapability.Utils.Lang 1205 * @crossplatform 1206 * @since 10 1207 */ 1208 /** 1209 * Priority of the calling thread. If the return value is empty, no task is running. 1210 * 1211 * @type { ?Priority } 1212 * @syscap SystemCapability.Utils.Lang 1213 * @crossplatform 1214 * @atomicservice 1215 * @since 11 1216 */ 1217 priority?: Priority; 1218 } 1219 1220 /** 1221 * Indicates the internal information of the taskpool. 1222 * 1223 * @syscap SystemCapability.Utils.Lang 1224 * @crossplatform 1225 * @since 10 1226 */ 1227 /** 1228 * Describes the internal information about a task pool. 1229 * 1230 * @syscap SystemCapability.Utils.Lang 1231 * @crossplatform 1232 * @atomicservice 1233 * @since 11 1234 */ 1235 class TaskPoolInfo { 1236 /** 1237 * An array of taskpool thread information. 1238 * 1239 * @type { ThreadInfo[] } 1240 * @syscap SystemCapability.Utils.Lang 1241 * @crossplatform 1242 * @since 10 1243 */ 1244 /** 1245 * Internal information about the worker threads. 1246 * 1247 * @type { ThreadInfo[] } 1248 * @syscap SystemCapability.Utils.Lang 1249 * @crossplatform 1250 * @atomicservice 1251 * @since 11 1252 */ 1253 threadInfos: ThreadInfo[]; 1254 1255 /** 1256 * An array of taskpool task information. 1257 * 1258 * @type { TaskInfo[] } 1259 * @syscap SystemCapability.Utils.Lang 1260 * @crossplatform 1261 * @since 10 1262 */ 1263 /** 1264 * Internal information about the tasks. 1265 * 1266 * @type { TaskInfo[] } 1267 * @syscap SystemCapability.Utils.Lang 1268 * @crossplatform 1269 * @atomicservice 1270 * @since 11 1271 */ 1272 taskInfos: TaskInfo[]; 1273 } 1274 1275 /** 1276 * Execute a concurrent function. 1277 * 1278 * @param { Function } func - func func Concurrent function want to execute. 1279 * @param { unknown[] } args - args args The concurrent function arguments. 1280 * @returns { Promise<unknown> } 1281 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1282 * 1.Mandatory parameters are left unspecified; 1283 * 2.Incorrect parameter types; 1284 * 3.Parameter verification failed. 1285 * @throws { BusinessError } 10200003 - Worker initialization failed. 1286 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1287 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1288 * @syscap SystemCapability.Utils.Lang 1289 * @since 9 1290 */ 1291 /** 1292 * Execute a concurrent function. 1293 * 1294 * @param { Function } func - func func Concurrent function want to execute. 1295 * @param { unknown[] } args - args args The concurrent function arguments. 1296 * @returns { Promise<unknown> } 1297 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1298 * 1.Mandatory parameters are left unspecified; 1299 * 2.Incorrect parameter types; 1300 * 3.Parameter verification failed. 1301 * @throws { BusinessError } 10200003 - Worker initialization failed. 1302 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1303 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1304 * @syscap SystemCapability.Utils.Lang 1305 * @crossplatform 1306 * @since 10 1307 */ 1308 /** 1309 * Execute a concurrent function. 1310 * 1311 * @param { Function } func - func func Concurrent function want to execute. 1312 * @param { Object[] } args - args args The concurrent function arguments. 1313 * @returns { Promise<Object> } 1314 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1315 * 1.Mandatory parameters are left unspecified; 1316 * 2.Incorrect parameter types; 1317 * 3.Parameter verification failed. 1318 * @throws { BusinessError } 10200003 - Worker initialization failed. 1319 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1320 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1321 * @syscap SystemCapability.Utils.Lang 1322 * @crossplatform 1323 * @atomicservice 1324 * @since 11 1325 */ 1326 /** 1327 * Places a function to be executed in the internal queue of the task pool. The function is not executed immediately. 1328 * It waits to be distributed to the worker thread for execution. In this mode, the function cannot be canceled. 1329 * 1330 * @param { Function } func - Function to be executed. The function must be decorated using @Concurrent. 1331 * For details about the supported return value types of the function, see Sequenceable Data Types. 1332 * @param { Object[] } args - Arguments of the function. For details about the supported parameter types, 1333 * see Sequenceable Data Types. The default value is undefined. 1334 * @returns { Promise<Object> } 1335 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1336 * 1.Mandatory parameters are left unspecified; 1337 * 2.Incorrect parameter types; 1338 * 3.Parameter verification failed. 1339 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1340 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1341 * @syscap SystemCapability.Utils.Lang 1342 * @crossplatform 1343 * @atomicservice 1344 * @since 12 1345 */ 1346 function execute(func: Function, ...args: Object[]): Promise<Object>; 1347 1348 /** 1349 * Execute a concurrent function with generics. 1350 * 1351 * @param { (...args: A) => R | Promise<R> } func - Concurrent function want to execute. 1352 * @param { A } args - The concurrent function arguments. 1353 * @returns { Promise<R> } 1354 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1355 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1356 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1357 * @syscap SystemCapability.Utils.Lang 1358 * @atomicservice 1359 * @since 13 1360 */ 1361 /** 1362 * Verifies the passed-in parameter types and return value type of a concurrent function, 1363 * and places the function to execute in the internal queue of the task pool. 1364 * 1365 * @param { (...args: A) => R | Promise<R> } func - Function to be executed. The function must be decorated using @Concurrent. 1366 * For details about the supported return value types of the function, see Sequenceable Data Types. 1367 * @param { A } args - Arguments of the function. For details about the supported parameter types, 1368 * see Sequenceable Data Types. The default value is undefined. 1369 * @returns { Promise<R> } 1370 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1371 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1372 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1373 * @syscap SystemCapability.Utils.Lang 1374 * @crossplatform 1375 * @atomicservice 1376 * @since 18 1377 */ 1378 function execute<A extends Array<Object>, R>(func: (...args: A) => R | Promise<R>, ...args: A): Promise<R>; 1379 1380 /** 1381 * Execute a concurrent task. 1382 * 1383 * @param { Task } task - task task The task want to execute. 1384 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1385 * @returns { Promise<unknown> } 1386 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1387 * 1.Mandatory parameters are left unspecified; 1388 * 2.Incorrect parameter types; 1389 * 3.Parameter verification failed. 1390 * @throws { BusinessError } 10200003 - Worker initialization failed. 1391 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1392 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1393 * @syscap SystemCapability.Utils.Lang 1394 * @since 9 1395 */ 1396 /** 1397 * Execute a concurrent task. 1398 * 1399 * @param { Task } task - task task The task want to execute. 1400 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1401 * @returns { Promise<unknown> } 1402 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1403 * 1.Mandatory parameters are left unspecified; 1404 * 2.Incorrect parameter types; 1405 * 3.Parameter verification failed. 1406 * @throws { BusinessError } 10200003 - Worker initialization failed. 1407 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1408 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1409 * @syscap SystemCapability.Utils.Lang 1410 * @crossplatform 1411 * @since 10 1412 */ 1413 /** 1414 * Execute a concurrent task. 1415 * 1416 * @param { Task } task - task task The task want to execute. 1417 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1418 * @returns { Promise<Object> } 1419 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1420 * 1.Mandatory parameters are left unspecified; 1421 * 2.Incorrect parameter types; 1422 * 3.Parameter verification failed. 1423 * @throws { BusinessError } 10200003 - Worker initialization failed. 1424 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1425 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1426 * @syscap SystemCapability.Utils.Lang 1427 * @crossplatform 1428 * @atomicservice 1429 * @since 11 1430 */ 1431 /** 1432 * Execute a concurrent task. 1433 * 1434 * @param { Task } task - The task want to execute. 1435 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1436 * @returns { Promise<Object> } 1437 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1438 * <br>1. Mandatory parameters are left unspecified; 1439 * <br>2. Incorrect parameter types; 1440 * <br>3. Parameter verification failed. 1441 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1442 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1443 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1444 * @syscap SystemCapability.Utils.Lang 1445 * @crossplatform 1446 * @atomicservice 1447 * @since 12 1448 */ 1449 /** 1450 * Places a task in the internal queue of the task pool. The task is not executed immediately. It waits to be distributed 1451 * to the worker thread for execution. In this mode, you can set the task priority and call cancel() to cancel the task. 1452 * The task cannot be a task in a task group, serial queue, or asynchronous queue. This API can be called only once for 1453 * a continuous task, but multiple times for a non-continuous task. 1454 * 1455 * @param { Task } task - Task to be executed. 1456 * @param { Priority } [priority] - Priority of the task. The default value is taskpool.Priority.MEDIUM. 1457 * @returns { Promise<Object> } 1458 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1459 * <br>1. Mandatory parameters are left unspecified; 1460 * <br>2. Incorrect parameter types; 1461 * <br>3. Parameter verification failed. 1462 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1463 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1464 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1465 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1466 * @syscap SystemCapability.Utils.Lang 1467 * @crossplatform 1468 * @atomicservice 1469 * @since 18 1470 */ 1471 function execute(task: Task, priority?: Priority): Promise<Object>; 1472 1473 /** 1474 * Execute a concurrent task with generics. 1475 * 1476 * @param { GenericsTask<A, R> } task - The task want to execute. 1477 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1478 * @returns { Promise<R> } 1479 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1480 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1481 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1482 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1483 * @syscap SystemCapability.Utils.Lang 1484 * @atomicservice 1485 * @since 13 1486 */ 1487 /** 1488 * Verifies the passed-in parameter types and return value type of a concurrent function, and places the generic task in the internal queue of the task pool. 1489 * 1490 * @param { GenericsTask<A, R> } task - Generic task to be executed. 1491 * @param { Priority } [priority] - Priority of the task. The default value is taskpool.Priority.MEDIUM. 1492 * @returns { Promise<R> } 1493 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1494 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1495 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1496 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1497 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1498 * @syscap SystemCapability.Utils.Lang 1499 * @crossplatform 1500 * @atomicservice 1501 * @since 18 1502 */ 1503 function execute<A extends Array<Object>, R>(task: GenericsTask<A, R>, priority?: Priority): Promise<R>; 1504 1505 /** 1506 * Execute a concurrent task group. 1507 * 1508 * @param { TaskGroup } group - group group The task group want to execute. 1509 * @param { Priority } [priority] - priority priority Task group priority, MEDIUM is default. 1510 * @returns { Promise<unknown[]> } 1511 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1512 * 1.Mandatory parameters are left unspecified; 1513 * 2.Incorrect parameter types; 1514 * 3.Parameter verification failed. 1515 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1516 * @syscap SystemCapability.Utils.Lang 1517 * @crossplatform 1518 * @since 10 1519 */ 1520 /** 1521 * Places a task group in the internal queue of the task pool. The tasks in the task group are not executed immediately. 1522 * They wait to be distributed to the worker thread for execution. After all tasks in the task group are executed, 1523 * a result array is returned. This API applies when you want to execute a group of associated tasks. 1524 * 1525 * @param { TaskGroup } group - Task group to be executed. 1526 * @param { Priority } [priority] - Priority of the task group. The default value is taskpool.Priority.MEDIUM. 1527 * @returns { Promise<Object[]> } 1528 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1529 * 1.Mandatory parameters are left unspecified; 1530 * 2.Incorrect parameter types; 1531 * 3.Parameter verification failed. 1532 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1533 * @syscap SystemCapability.Utils.Lang 1534 * @crossplatform 1535 * @atomicservice 1536 * @since 11 1537 */ 1538 function execute(group: TaskGroup, priority?: Priority): Promise<Object[]>; 1539 1540 /** 1541 * Execute a concurrent task after the specified time. 1542 * 1543 * @param { number } delayTime - delayTime delayTime The time want to delay. 1544 * @param { Task } task - task task The task want to execute. 1545 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1546 * @returns { Promise<Object> } 1547 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1548 * 1.Mandatory parameters are left unspecified; 1549 * 2.Incorrect parameter types; 1550 * 3.Parameter verification failed. 1551 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1552 * @syscap SystemCapability.Utils.Lang 1553 * @crossplatform 1554 * @atomicservice 1555 * @since 11 1556 */ 1557 /** 1558 * Execute a concurrent task after the specified time. 1559 * 1560 * @param { number } delayTime - The time want to delay. 1561 * @param { Task } task - The task want to execute. 1562 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1563 * @returns { Promise<Object> } 1564 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1565 * <br>1. Mandatory parameters are left unspecified; 1566 * <br>2. Incorrect parameter types; 1567 * <br>3. Parameter verification failed. 1568 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1569 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1570 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1571 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1572 * @syscap SystemCapability.Utils.Lang 1573 * @crossplatform 1574 * @atomicservice 1575 * @since 12 1576 */ 1577 /** 1578 * Executes a task after a given delay. In this mode, you can set the task priority and call cancel() to cancel the task. 1579 * The task cannot be a task in a task group, serial queue, or asynchronous queue, or a periodic task. 1580 * This API can be called only once for a continuous task, but multiple times for a non-continuous task. 1581 * 1582 * @param { number } delayTime - Delay, in ms. 1583 * @param { Task } task - Task to be executed with a delay. 1584 * @param { Priority } [priority] - Priority of the task. The default value is taskpool.Priority.MEDIUM. 1585 * @returns { Promise<Object> } 1586 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1587 * <br>1. Mandatory parameters are left unspecified; 1588 * <br>2. Incorrect parameter types; 1589 * <br>3. Parameter verification failed. 1590 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1591 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1592 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1593 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1594 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1595 * @syscap SystemCapability.Utils.Lang 1596 * @crossplatform 1597 * @atomicservice 1598 * @since 18 1599 */ 1600 function executeDelayed(delayTime: number, task: Task, priority?: Priority): Promise<Object>; 1601 1602 /** 1603 * Execute a concurrent task with generics after the specified time. 1604 * 1605 * @param { number } delayTime - The time want to delay. 1606 * @param { GenericsTask<A, R> } task - The task want to execute. 1607 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1608 * @returns { Promise<R> } 1609 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1610 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1611 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1612 * @syscap SystemCapability.Utils.Lang 1613 * @atomicservice 1614 * @since 13 1615 */ 1616 /** 1617 * Verifies the passed-in parameter types and return value type of a concurrent function, and executes the generic task with a delay. 1618 * 1619 * @param { number } delayTime - Delay, in ms. 1620 * @param { GenericsTask<A, R> } task - Generic task to be executed with a delay. 1621 * @param { Priority } [priority] - Priority of the task. The default value is taskpool.Priority.MEDIUM. 1622 * @returns { Promise<R> } 1623 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1624 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1625 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1626 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1627 * @syscap SystemCapability.Utils.Lang 1628 * @crossplatform 1629 * @atomicservice 1630 * @since 18 1631 */ 1632 function executeDelayed<A extends Array<Object>, R>(delayTime: number, task: GenericsTask<A, R>, priority?: Priority): Promise<R>; 1633 1634 /** 1635 * Execute a concurrent task periodically. 1636 * 1637 * @param { number } period - The period in milliseconds for executing task. 1638 * @param { Task } task - The task want to execute. 1639 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1640 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1641 * <br>1. Mandatory parameters are left unspecified; 1642 * <br>2. Incorrect parameter types; 1643 * <br>3. Parameter verification failed. 1644 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1645 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1646 * @throws { BusinessError } 10200028 - The period is less than zero. 1647 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1648 * @syscap SystemCapability.Utils.Lang 1649 * @crossplatform 1650 * @atomicservice 1651 * @since 12 1652 */ 1653 /** 1654 * Executes a task periodically. In this execution mode, you can set the task priority and call cancel() to cancel the execution. 1655 * A periodic task cannot be a task in a task group, serial queue, or asynchronous queue. It cannot call execute() again or have a dependency relationship. 1656 * 1657 * @param { number } period - Execution period, in ms. 1658 * @param { Task } task - Task to be executed. 1659 * @param { Priority } [priority] - Priority of the task. The default value is taskpool.Priority.MEDIUM. 1660 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1661 * <br>1. Mandatory parameters are left unspecified; 1662 * <br>2. Incorrect parameter types; 1663 * <br>3. Parameter verification failed. 1664 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1665 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1666 * @throws { BusinessError } 10200028 - The period is less than zero. 1667 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1668 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1669 * @syscap SystemCapability.Utils.Lang 1670 * @crossplatform 1671 * @atomicservice 1672 * @since 18 1673 */ 1674 function executePeriodically(period: number, task: Task, priority?: Priority): void; 1675 1676 /** 1677 * Execute a concurrent task with generics periodically. 1678 * 1679 * @param { number } period - The period in milliseconds for executing task. 1680 * @param { GenericsTask<A, R> } task - The task want to execute. 1681 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1682 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1683 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1684 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1685 * @throws { BusinessError } 10200028 - The period is less than zero. 1686 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1687 * @syscap SystemCapability.Utils.Lang 1688 * @atomicservice 1689 * @since 13 1690 */ 1691 /** 1692 * Verifies the passed-in parameter types and return value type of a concurrent function, and executes the generic task 1693 * periodically at an interval specified by period. 1694 * 1695 * @param { number } period - Execution period, in ms. 1696 * @param { GenericsTask<A, R> } task - Generic task to be executed periodically. 1697 * @param { Priority } [priority] - Priority of the task. The default value is taskpool.Priority.MEDIUM. 1698 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1699 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1700 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1701 * @throws { BusinessError } 10200028 - The period is less than zero. 1702 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1703 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1704 * @syscap SystemCapability.Utils.Lang 1705 * @crossplatform 1706 * @atomicservice 1707 * @since 18 1708 */ 1709 function executePeriodically<A extends Array<Object>, R>(period: number, task: GenericsTask<A, R>, priority?: Priority): void; 1710 1711 /** 1712 * Cancel a concurrent task. 1713 * 1714 * @param { Task } task - task task The task want to cancel. 1715 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1716 * 1.Mandatory parameters are left unspecified; 1717 * 2.Incorrect parameter types; 1718 * 3.Parameter verification failed. 1719 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1720 * @throws { BusinessError } 10200016 - The task to cancel is being executed. 1721 * @syscap SystemCapability.Utils.Lang 1722 * @since 9 1723 */ 1724 /** 1725 * Cancel a concurrent task. 1726 * 1727 * @param { Task } task - task task The task want to cancel. 1728 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1729 * 1.Mandatory parameters are left unspecified; 1730 * 2.Incorrect parameter types; 1731 * 3.Parameter verification failed. 1732 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1733 * @syscap SystemCapability.Utils.Lang 1734 * @crossplatform 1735 * @since 10 1736 */ 1737 /** 1738 * Cancel a concurrent task. 1739 * 1740 * @param { Task } task - task task The task want to cancel. 1741 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1742 * 1.Mandatory parameters are left unspecified; 1743 * 2.Incorrect parameter types; 1744 * 3.Parameter verification failed. 1745 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1746 * @syscap SystemCapability.Utils.Lang 1747 * @crossplatform 1748 * @atomicservice 1749 * @since 11 1750 */ 1751 /** 1752 * Cancels a task in the task pool. If the task is in the internal queue of the task pool, the task will not be executed 1753 * after being canceled, and an exception indicating task cancellation is returned. If the task has been distributed to 1754 * the worker thread of the task pool, canceling the task does not affect the task execution, and the execution result 1755 * is returned in the catch branch. You can use isCanceled() to check the task cancellation status. In other words, 1756 * taskpool.cancel takes effect before taskpool.execute or taskpool.executeDelayed is called. 1757 * 1758 * @param { Task } task - Task to cancel. 1759 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1760 * @throws { BusinessError } 10200055 - The asyncRunner task has been canceled. 1761 * @syscap SystemCapability.Utils.Lang 1762 * @crossplatform 1763 * @atomicservice 1764 * @since 18 1765 */ 1766 function cancel(task: Task): void; 1767 1768 /** 1769 * Cancel a concurrent task group. 1770 * 1771 * @param { TaskGroup } group - group group The task group want to cancel. 1772 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1773 * 1.Mandatory parameters are left unspecified; 1774 * 2.Incorrect parameter types; 1775 * 3.Parameter verification failed. 1776 * @throws { BusinessError } 10200018 - The task group to cancel does not exist. 1777 * @syscap SystemCapability.Utils.Lang 1778 * @crossplatform 1779 * @since 10 1780 */ 1781 /** 1782 * Cancels a task group in the task pool. If a task group is canceled before all the tasks in it are finished, undefined is returned. 1783 * 1784 * @param { TaskGroup } group - Task group to cancel. 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 } 10200018 - The task group to cancel does not exist. 1790 * @syscap SystemCapability.Utils.Lang 1791 * @crossplatform 1792 * @atomicservice 1793 * @since 11 1794 */ 1795 function cancel(group: TaskGroup): void; 1796 1797 /** 1798 * Cancels a task in the task pool by task ID. If the task is in the internal queue of the task pool, 1799 * the task will not be executed after being canceled, and an exception indicating task cancellation is returned. 1800 * If the task has been distributed to the worker thread of the task pool, canceling the task does not affect the task execution, 1801 * and the execution result is returned in the catch branch. You can use isCanceled() to check the task cancellation status. 1802 * In other words, taskpool.cancel takes effect before taskpool.execute or taskpool.executeDelayed is called. 1803 * If taskpool.cancel is called by other threads, note that the cancel operation, which is asynchronous, 1804 * may take effect for later calls of taskpool.execute or taskpool.executeDelayed. 1805 * 1806 * @param { number } taskId - ID of the task to cancel. 1807 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1808 * @throws { BusinessError } 10200055 - The asyncRunner task has been canceled. 1809 * @syscap SystemCapability.Utils.Lang 1810 * @atomicservice 1811 * @since 18 1812 */ 1813 function cancel(taskId: number): void; 1814 1815 /** 1816 * Get task pool internal information. 1817 * 1818 * @returns { TaskPoolInfo } 1819 * @syscap SystemCapability.Utils.Lang 1820 * @crossplatform 1821 * @since 10 1822 */ 1823 /** 1824 * Obtains internal information about this task pool, including thread information and task information. 1825 * 1826 * @returns { TaskPoolInfo } 1827 * @syscap SystemCapability.Utils.Lang 1828 * @crossplatform 1829 * @atomicservice 1830 * @since 11 1831 */ 1832 function getTaskPoolInfo(): TaskPoolInfo; 1833 1834 /** 1835 * Terminates a continuous task in the task pool. It is called after the continuous task is complete. 1836 * After the task is terminated, the thread that executes the task may be reclaimed. 1837 * 1838 * @param { LongTask } longTask - Continuous task to terminate. 1839 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1840 * 1.Mandatory parameters are left unspecified; 1841 * 2.Incorrect parameter types; 1842 * 3.Parameter verification failed. 1843 * @syscap SystemCapability.Utils.Lang 1844 * @crossplatform 1845 * @atomicservice 1846 * @since 12 1847 */ 1848 function terminateTask(longTask: LongTask): void; 1849 1850 /** 1851 * Checks whether a function is a concurrent function. 1852 * 1853 * @param { Function } func - Function to check. 1854 * @returns { boolean } Returns {@code true} if it is a concurrent function; returns {@code false} otherwise. 1855 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1856 * 1.Mandatory parameters are left unspecified; 1857 * 2.Incorrect parameter types; 1858 * 3.Parameter verification failed. 1859 * @syscap SystemCapability.Utils.Lang 1860 * @crossplatform 1861 * @atomicservice 1862 * @since 12 1863 */ 1864 function isConcurrent(func: Function): boolean; 1865 1866 /** 1867 * Implements an asynchronous queue, for which you can specify the task execution concurrency and queuing policy. 1868 * Before calling any APIs in AsyncRunner, you must use constructor to create an AsyncRunner instance. 1869 * 1870 * @syscap SystemCapability.Utils.Lang 1871 * @atomicservice 1872 * @since 18 1873 */ 1874 export class AsyncRunner { 1875 /** 1876 * A constructor used to create an AsyncRunner instance. It constructs a non-global asynchronous queue. 1877 * Even when the parameters passed are the same, it returns different asynchronous queues. 1878 * 1879 * @param { number } runningCapacity - Maximum number of tasks that can run concurrently. The value must be a positive integer. 1880 * If a negative number is passed, an error is reported. If a non-integer is passed, the value is rounded down. 1881 * @param { ?number } waitingCapacity - Maximum number of tasks that can be queued. The value must be greater than or equal to 0. 1882 * If a negative number is passed, an error is reported. If a non-integer is passed, the value is rounded down. 1883 * The default value is 0, indicating that there is no limit to the number of tasks that can wait. 1884 * If a value greater than 0 is passed, tasks will be discarded from the front of the queue once the queue size 1885 * exceeds this limit, implementing a discard policy. 1886 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 1887 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 1888 * @syscap SystemCapability.Utils.Lang 1889 * @atomicservice 1890 * @since 18 1891 */ 1892 constructor(runningCapacity: number, waitingCapacity?: number); 1893 1894 /** 1895 * A constructor used to create an AsyncRunner instance. It constructs a global asynchronous queue. 1896 * If the passed-in name is the same as an existing name, the same asynchronous queue is returned. 1897 * NOTE: 1898 * 1.The bottom layer uses the singleton mode to ensure that the same instance is obtained when an asynchronous queue with the same name is created. 1899 * 2.The task execution concurrency and waiting capacity cannot be modified. 1900 * 1901 * @param { string } name - Name of an asynchronous queue. 1902 * @param { number } runningCapacity - Maximum number of tasks that can run concurrently. The value must be a positive integer. 1903 * If a negative number is passed, an error is reported. If a non-integer is passed, the value is rounded down. 1904 * @param { ?number } waitingCapacity - Maximum number of tasks that can be queued. The value must be greater than or equal to 0. 1905 * If a negative number is passed, an error is reported. If a non-integer is passed, the value is rounded down. 1906 * The default value is 0, indicating that there is no limit to the number of tasks that can wait. 1907 * If a value greater than 0 is passed, tasks will be discarded from the front of the queue once the queue size 1908 * exceeds this limit, implementing a discard policy. 1909 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 1910 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 1911 * @syscap SystemCapability.Utils.Lang 1912 * @atomicservice 1913 * @since 18 1914 */ 1915 constructor(name: string, runningCapacity: number, waitingCapacity?: number); 1916 1917 /** 1918 * Adds a task to the asynchronous queue for execution. Before using this API, you must create an AsyncRunner instance. 1919 * NOTE: 1920 * Tasks in a task group cannot be added to the asynchronous queue. 1921 * Tasks in a serial queue cannot be added to the asynchronous queue. 1922 * Tasks in other asynchronous queues cannot be added to the asynchronous queue. 1923 * Periodic tasks cannot be added to the asynchronous queue. 1924 * Delayed tasks cannot be added to the asynchronous queue. 1925 * Tasks that depend others cannot be added to the asynchronous queue. 1926 * Tasks that have been executed cannot be added to the asynchronous queue. 1927 * 1928 * @param { Task } task - Task to be added to the asynchronous queue. 1929 * @param { ?Priority } [priority] - Priority of the task. The default value is taskpool.Priority.MEDIUM. 1930 * @returns { Promise<Object> } 1931 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1932 * @throws { BusinessError } 10200025 - dependent task not allowed. 1933 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1934 * @throws { BusinessError } 10200054 - The asyncRunner task is discarded. 1935 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1936 * @syscap SystemCapability.Utils.Lang 1937 * @atomicservice 1938 * @since 18 1939 */ 1940 execute(task: Task, priority?: Priority): Promise<Object>; 1941 } 1942 1943 /** 1944 * Defines the task result interface 1945 * 1946 * @interface TaskResult 1947 * @syscap SystemCapability.Utils.Lang 1948 * @crossplatform 1949 * @atomicservice 1950 * @since 20 1951 */ 1952 interface TaskResult { 1953 /** 1954 * the result returned by the task 1955 * 1956 * @type { ?Object } 1957 * @syscap SystemCapability.Utils.Lang 1958 * @crossplatform 1959 * @atomicservice 1960 * @since 20 1961 */ 1962 result?: Object; 1963 1964 /** 1965 * the error thrown by the task 1966 * 1967 * @type { ?(Error | Object) } 1968 * @syscap SystemCapability.Utils.Lang 1969 * @crossplatform 1970 * @atomicservice 1971 * @since 20 1972 */ 1973 error?: Error | Object; 1974 } 1975} 1976 1977export default taskpool; 1978