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 * The Priority defines the task priority. 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 * set task priority to high. 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 * set task priority to medium. 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 * set task priority to low. 132 * 133 * @syscap SystemCapability.Utils.Lang 134 * @crossplatform 135 * @atomicservice 136 * @since 11 137 */ 138 LOW = 2, 139 /** 140 * set task priority to idle. 141 * 142 * @syscap SystemCapability.Utils.Lang 143 * @crossplatform 144 * @atomicservice 145 * @since 12 146 */ 147 IDLE = 3 148 } 149 150 /** 151 * Indicates the type of callback to be registered. 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 * Indicates the type of callback with error code to be registered. 163 * 164 * @typedef { function } CallbackFunctionWithError 165 * @param { Error } e - the 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 * The Task class provides an interface to create a task. 188 * 189 * @syscap SystemCapability.Utils.Lang 190 * @crossplatform 191 * @atomicservice 192 * @since 11 193 */ 194 class Task { 195 /** 196 * Create a Task instance. 197 * 198 * @param { Function } func - func func Concurrent function to execute in taskpool. 199 * @param { unknown[] } args - args args The concurrent function arguments. 200 * @throws { BusinessError } 401 - The input parameters are invalid. 201 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 202 * @syscap SystemCapability.Utils.Lang 203 * @since 9 204 */ 205 /** 206 * Create a Task instance. 207 * 208 * @param { Function } func - func func Concurrent function to execute in taskpool. 209 * @param { unknown[] } args - args args The concurrent function arguments. 210 * @throws { BusinessError } 401 - The input parameters are invalid. 211 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 212 * @syscap SystemCapability.Utils.Lang 213 * @crossplatform 214 * @since 10 215 */ 216 /** 217 * Create a Task instance. 218 * 219 * @param { Function } func - func func Concurrent function to execute in taskpool. 220 * @param { Object[] } args - args args The concurrent function arguments. 221 * @throws { BusinessError } 401 - The input parameters are invalid. 222 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 223 * @syscap SystemCapability.Utils.Lang 224 * @crossplatform 225 * @atomicservice 226 * @since 11 227 */ 228 constructor(func: Function, ...args: Object[]); 229 230 /** 231 * Create a Task instance. 232 * 233 * @param { string } name - name name The name of Task. 234 * @param { Function } func - func func Concurrent function to execute in taskpool. 235 * @param { Object[] } args - args args The concurrent function arguments. 236 * @throws { BusinessError } 401 - The input parameters are invalid. 237 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 238 * @syscap SystemCapability.Utils.Lang 239 * @crossplatform 240 * @atomicservice 241 * @since 11 242 */ 243 constructor(name: string, func: Function, ...args: Object[]); 244 245 /** 246 * Check current running Task is canceled or not. 247 * 248 * @returns { boolean } Returns {@code true} if current running task is canceled; returns {@code false} otherwise. 249 * @static 250 * @syscap SystemCapability.Utils.Lang 251 * @crossplatform 252 * @since 10 253 */ 254 /** 255 * Check current running Task is canceled or not. 256 * 257 * @returns { boolean } Returns {@code true} if current running task is canceled; returns {@code false} otherwise. 258 * @static 259 * @syscap SystemCapability.Utils.Lang 260 * @crossplatform 261 * @atomicservice 262 * @since 11 263 */ 264 static isCanceled(): boolean; 265 266 /** 267 * Send data back to the host side and trigger the registered callback 268 * 269 * @param { Object[] } args - Data to be used as the input parameter of the registered callback. 270 * @throws { BusinessError } 401 - The input parameters are invalid. 271 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 272 * @throws { BusinessError } 10200022 - The function is not called in the TaskPool thread. 273 * @throws { BusinessError } 10200023 - The function is not called in the concurrent function. 274 * @throws { BusinessError } 10200024 - The callback is not registered on the host side. 275 * @static 276 * @syscap SystemCapability.Utils.Lang 277 * @crossplatform 278 * @atomicservice 279 * @since 11 280 */ 281 static sendData(...args: Object[]): void; 282 283 /** 284 * Set transfer list for this task. 285 * 286 * @param { ArrayBuffer[] } [transfer] - transfer Transfer list of this task, empty array is default. 287 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 288 * @syscap SystemCapability.Utils.Lang 289 * @crossplatform 290 * @since 10 291 */ 292 /** 293 * Set transfer list for this task. 294 * 295 * @param { ArrayBuffer[] } [transfer] - transfer Transfer list of this task, empty array is default. 296 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 297 * @throws { BusinessError } 10200029 - An ArrayBuffer cannot be set as both a transfer list and a clone list. 298 * @syscap SystemCapability.Utils.Lang 299 * @crossplatform 300 * @atomicservice 301 * @since 11 302 */ 303 setTransferList(transfer?: ArrayBuffer[]): void; 304 305 /** 306 * Set clone list for this task. 307 * 308 * @param { Object[] | ArrayBuffer[] } cloneList - Sendable objects or arrayBuffer objects in this list 309 * will be transmitted to worker thread in a copy way. 310 * @throws { BusinessError } 401 - Parameter error. Possible causes: 311 * 1.Mandatory parameters are left unspecified; 312 * 2.Incorrect parameter types; 313 * 3.Parameter verification failed. 314 * @throws { BusinessError } 10200029 - An ArrayBuffer cannot be set as both a transfer list and a clone list. 315 * @syscap SystemCapability.Utils.Lang 316 * @crossplatform 317 * @atomicservice 318 * @since 11 319 */ 320 setCloneList(cloneList: Object[] | ArrayBuffer[]): void; 321 322 /** 323 * Register a callback for this task to receive and handle data from the taskpool worker thread. 324 * 325 * @param { Function } [callback] - Callback to be registered and executed later on the host side. 326 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 327 * @syscap SystemCapability.Utils.Lang 328 * @crossplatform 329 * @atomicservice 330 * @since 11 331 */ 332 onReceiveData(callback?: Function): void; 333 334 /** 335 * Add dependencies on the task array for this task. 336 * 337 * @param { Task[] } tasks - tasks tasks An array of dependent tasks. 338 * @throws { BusinessError } 401 - Parameter error. Possible causes: 339 * 1.Mandatory parameters are left unspecified; 340 * 2.Incorrect parameter types; 341 * 3.Parameter verification failed. 342 * @throws { BusinessError } 10200026 - There is a circular dependency. 343 * @syscap SystemCapability.Utils.Lang 344 * @crossplatform 345 * @atomicservice 346 * @since 11 347 */ 348 /** 349 * Add dependencies on the task array for this task. 350 * 351 * @param { Task[] } tasks - An array of dependent tasks. 352 * @throws { BusinessError } 401 - Parameter error. Possible causes: 353 * <br>1. Mandatory parameters are left unspecified; 354 * <br>2. Incorrect parameter types; 355 * <br>3. Parameter verification failed. 356 * @throws { BusinessError } 10200026 - There is a circular dependency. 357 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 358 * @syscap SystemCapability.Utils.Lang 359 * @crossplatform 360 * @atomicservice 361 * @since 12 362 */ 363 /** 364 * Add dependencies on the task array for this task. 365 * 366 * @param { Task[] } tasks - An array of dependent tasks. 367 * @throws { BusinessError } 401 - Parameter error. Possible causes: 368 * <br>1. Mandatory parameters are left unspecified; 369 * <br>2. Incorrect parameter types; 370 * <br>3. Parameter verification failed. 371 * @throws { BusinessError } 10200026 - There is a circular dependency. 372 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 373 * @throws { BusinessError } 10200056 - The task has been executed by the AsyncRunner. 374 * @syscap SystemCapability.Utils.Lang 375 * @crossplatform 376 * @atomicservice 377 * @since 18 378 */ 379 addDependency(...tasks: Task[]): void; 380 381 /** 382 * Remove dependencies on the task array for this task. 383 * 384 * @param { Task[] } tasks - tasks tasks An array of dependent tasks. 385 * @throws { BusinessError } 401 - Parameter error. Possible causes: 386 * 1.Mandatory parameters are left unspecified; 387 * 2.Incorrect parameter types; 388 * 3.Parameter verification failed. 389 * @throws { BusinessError } 10200027 - The dependency does not exist. 390 * @syscap SystemCapability.Utils.Lang 391 * @crossplatform 392 * @atomicservice 393 * @since 11 394 */ 395 /** 396 * Remove dependencies on the task array for this task. 397 * 398 * @param { Task[] } tasks - An array of dependent tasks. 399 * @throws { BusinessError } 401 - Parameter error. Possible causes: 400 * <br>1. Mandatory parameters are left unspecified; 401 * <br>2. Incorrect parameter types; 402 * <br>3. Parameter verification failed. 403 * @throws { BusinessError } 10200027 - The dependency does not exist. 404 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 405 * @syscap SystemCapability.Utils.Lang 406 * @crossplatform 407 * @atomicservice 408 * @since 12 409 */ 410 /** 411 * Remove dependencies on the task array for this task. 412 * 413 * @param { Task[] } tasks - An array of dependent tasks. 414 * @throws { BusinessError } 401 - Parameter error. Possible causes: 415 * <br>1. Mandatory parameters are left unspecified; 416 * <br>2. Incorrect parameter types; 417 * <br>3. Parameter verification failed. 418 * @throws { BusinessError } 10200027 - The dependency does not exist. 419 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 420 * @throws { BusinessError } 10200056 - The task has been executed by the AsyncRunner. 421 * @syscap SystemCapability.Utils.Lang 422 * @crossplatform 423 * @atomicservice 424 * @since 18 425 */ 426 removeDependency(...tasks: Task[]): void; 427 428 /** 429 * Register a callback and call it when the task is enqueued. 430 * 431 * @param { CallbackFunction } [callback] - Callback to be registered and executed later on the host side. 432 * @throws { BusinessError } 401 - The input parameters are invalid. 433 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 434 * @syscap SystemCapability.Utils.Lang 435 * @crossplatform 436 * @atomicservice 437 * @since 12 438 */ 439 onEnqueued(callback: CallbackFunction): void; 440 441 /** 442 * Register a callback and call it when the task before execute. 443 * 444 * @param { CallbackFunction } [callback] - Callback to be registered and executed later on the host side. 445 * @throws { BusinessError } 401 - The input parameters are invalid. 446 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 447 * @syscap SystemCapability.Utils.Lang 448 * @crossplatform 449 * @atomicservice 450 * @since 12 451 */ 452 onStartExecution(callback: CallbackFunction): void; 453 454 /** 455 * Register a callback and call it when the task fails to execute. 456 * 457 * @param { CallbackFunctionWithError } [callback] - Callback to be registered and executed later on the host side. 458 * @throws { BusinessError } 401 - The input parameters are invalid. 459 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 460 * @syscap SystemCapability.Utils.Lang 461 * @crossplatform 462 * @atomicservice 463 * @since 12 464 */ 465 onExecutionFailed(callback: CallbackFunctionWithError): void; 466 467 /** 468 * Register a callback and call it when the task successfully executes. 469 * 470 * @param { CallbackFunction } [callback] - Callback to be registered and executed later on the host side. 471 * @throws { BusinessError } 401 - The input parameters are invalid. 472 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 473 * @syscap SystemCapability.Utils.Lang 474 * @crossplatform 475 * @atomicservice 476 * @since 12 477 */ 478 onExecutionSucceeded(callback: CallbackFunction): void; 479 480 /** 481 * Check if the task has been completed. 482 * 483 * @returns { boolean } Returns {@code true} if the task has been completed; returns {@code false} otherwise. 484 * @syscap SystemCapability.Utils.Lang 485 * @crossplatform 486 * @atomicservice 487 * @since 12 488 */ 489 isDone(): boolean; 490 491 /** 492 * Concurrent function to execute in taskpool. 493 * 494 * @type { Function } 495 * @syscap SystemCapability.Utils.Lang 496 * @since 9 497 */ 498 /** 499 * Concurrent function to execute in taskpool. 500 * 501 * @type { Function } 502 * @syscap SystemCapability.Utils.Lang 503 * @crossplatform 504 * @since 10 505 */ 506 /** 507 * Concurrent function to execute in taskpool. 508 * 509 * @type { Function } 510 * @syscap SystemCapability.Utils.Lang 511 * @crossplatform 512 * @atomicservice 513 * @since 11 514 */ 515 function: Function; 516 517 /** 518 * The concurrent function arguments. 519 * 520 * @syscap SystemCapability.Utils.Lang 521 * @since 9 522 */ 523 /** 524 * The concurrent function arguments. 525 * 526 * @type { ?unknown[] } 527 * @syscap SystemCapability.Utils.Lang 528 * @crossplatform 529 * @since 10 530 */ 531 /** 532 * The concurrent function arguments. 533 * 534 * @type { ?Object[] } 535 * @syscap SystemCapability.Utils.Lang 536 * @crossplatform 537 * @atomicservice 538 * @since 11 539 */ 540 arguments?: Object[]; 541 542 /** 543 * Task name. 544 * 545 * @type { string } 546 * @syscap SystemCapability.Utils.Lang 547 * @crossplatform 548 * @atomicservice 549 * @since 11 550 */ 551 name: string; 552 553 /** 554 * Task identity. 555 * 556 * @type { number } 557 * @default 0 558 * @syscap SystemCapability.Utils.Lang 559 * @atomicservice 560 * @since 18 561 */ 562 taskId: number; 563 564 /** 565 * Total duration of task execution. 566 * 567 * @type { number } 568 * @default 0 569 * @syscap SystemCapability.Utils.Lang 570 * @crossplatform 571 * @atomicservice 572 * @since 11 573 */ 574 totalDuration: number; 575 576 /** 577 * IO duration of task execution. 578 * 579 * @type { number } 580 * @default 0 581 * @syscap SystemCapability.Utils.Lang 582 * @crossplatform 583 * @atomicservice 584 * @since 11 585 */ 586 ioDuration: number; 587 588 /** 589 * CPU duration of task execution. 590 * 591 * @type { number } 592 * @default 0 593 * @syscap SystemCapability.Utils.Lang 594 * @crossplatform 595 * @atomicservice 596 * @since 11 597 */ 598 cpuDuration: number; 599 } 600 601 /** 602 * The TaskGroup class provides an interface to create a task group. 603 * 604 * @syscap SystemCapability.Utils.Lang 605 * @crossplatform 606 * @since 10 607 */ 608 /** 609 * The TaskGroup class provides an interface to create a task group. 610 * 611 * @syscap SystemCapability.Utils.Lang 612 * @crossplatform 613 * @atomicservice 614 * @since 11 615 */ 616 class TaskGroup { 617 /** 618 * Create a TaskGroup instance. 619 * 620 * @syscap SystemCapability.Utils.Lang 621 * @crossplatform 622 * @since 10 623 */ 624 /** 625 * Create a TaskGroup instance. 626 * 627 * @syscap SystemCapability.Utils.Lang 628 * @crossplatform 629 * @atomicservice 630 * @since 11 631 */ 632 constructor(); 633 634 /** 635 * Create a TaskGroup instance. 636 * 637 * @param { string } name - name name The name of taskGroup. 638 * @throws { BusinessError } 401 - Parameter error. Possible causes: 639 * 1.Mandatory parameters are left unspecified; 640 * 2.Incorrect parameter types; 641 * 3.Parameter verification failed. 642 * @syscap SystemCapability.Utils.Lang 643 * @crossplatform 644 * @atomicservice 645 * @since 11 646 */ 647 constructor(name: string); 648 649 /** 650 * Add a Concurrent function into task group. 651 * 652 * @param { Function } func - func func Concurrent function to add in task group. 653 * @param { unknown[] } args - args args The concurrent function arguments. 654 * @throws { BusinessError } 401 - Parameter error. Possible causes: 655 * 1.Mandatory parameters are left unspecified; 656 * 2.Incorrect parameter types; 657 * 3.Parameter verification failed. 658 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 659 * @syscap SystemCapability.Utils.Lang 660 * @crossplatform 661 * @since 10 662 */ 663 /** 664 * Add a Concurrent function into task group. 665 * 666 * @param { Function } func - func func Concurrent function to add in task group. 667 * @param { Object[] } args - args args The concurrent function arguments. 668 * @throws { BusinessError } 401 - Parameter error. Possible causes: 669 * 1.Mandatory parameters are left unspecified; 670 * 2.Incorrect parameter types; 671 * 3.Parameter verification failed. 672 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 673 * @syscap SystemCapability.Utils.Lang 674 * @crossplatform 675 * @atomicservice 676 * @since 11 677 */ 678 addTask(func: Function, ...args: Object[]): void; 679 680 /** 681 * Add a Task into TaskGroup. 682 * 683 * @param { Task } task - task task The task want to add in task group. 684 * @throws { BusinessError } 401 - Parameter error. Possible causes: 685 * 1.Mandatory parameters are left unspecified; 686 * 2.Incorrect parameter types; 687 * 3.Parameter verification failed. 688 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 689 * @syscap SystemCapability.Utils.Lang 690 * @crossplatform 691 * @since 10 692 */ 693 /** 694 * Add a Task into TaskGroup. 695 * 696 * @param { Task } task - task task The task want to add in task group. 697 * @throws { BusinessError } 401 - Parameter error. Possible causes: 698 * 1.Mandatory parameters are left unspecified; 699 * 2.Incorrect parameter types; 700 * 3.Parameter verification failed. 701 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 702 * @syscap SystemCapability.Utils.Lang 703 * @crossplatform 704 * @atomicservice 705 * @since 11 706 */ 707 /** 708 * Add a Task into TaskGroup. 709 * 710 * @param { Task } task - The task want to add in task group. 711 * @throws { BusinessError } 401 - Parameter error. Possible causes: 712 * <br>1. Mandatory parameters are left unspecified; 713 * <br>2. Incorrect parameter types; 714 * <br>3. Parameter verification failed. 715 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 716 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 717 * @syscap SystemCapability.Utils.Lang 718 * @crossplatform 719 * @atomicservice 720 * @since 12 721 */ 722 /** 723 * Add a Task into TaskGroup. 724 * 725 * @param { Task } task - The task want to add in task group. 726 * @throws { BusinessError } 401 - Parameter error. Possible causes: 727 * <br>1. Mandatory parameters are left unspecified; 728 * <br>2. Incorrect parameter types; 729 * <br>3. Parameter verification failed. 730 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 731 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 732 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 733 * @syscap SystemCapability.Utils.Lang 734 * @crossplatform 735 * @atomicservice 736 * @since 18 737 */ 738 addTask(task: Task): void; 739 740 /** 741 * TaskGroup name. 742 * 743 * @type { string } 744 * @syscap SystemCapability.Utils.Lang 745 * @crossplatform 746 * @atomicservice 747 * @since 11 748 */ 749 name: string; 750 } 751 752 /** 753 * The SequenceRunner class provides an interface to create a task sequence runner. 754 * 755 * @syscap SystemCapability.Utils.Lang 756 * @crossplatform 757 * @atomicservice 758 * @since 11 759 */ 760 class SequenceRunner { 761 /** 762 * Create a SequenceRunner instance. 763 * 764 * @param { Priority } priority - Task execution priority, MEDIUM is default. 765 * @throws { BusinessError } 401 - Parameter error. Possible causes: 766 * 1.Incorrect parameter types; 767 * 2.Parameter verification failed. 768 * @syscap SystemCapability.Utils.Lang 769 * @crossplatform 770 * @atomicservice 771 * @since 11 772 */ 773 constructor(priority?: Priority); 774 775 /** 776 * Create or get a SequenceRunner instance by name. 777 * 778 * @param { string } name - SequenceRunner name, if name is the same, will return the same SequenceRunner. 779 * @param { Priority } priority - Task execution priority, MEDIUM is default. 780 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 781 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 782 * @syscap SystemCapability.Utils.Lang 783 * @crossplatform 784 * @atomicservice 785 * @since 12 786 */ 787 constructor(name: string, priority?: Priority); 788 789 /** 790 * Execute a concurrent function. 791 * 792 * @param { Task } task - The task want to execute. 793 * @returns { Promise<Object> } 794 * @throws { BusinessError } 401 - Parameter error. Possible causes: 795 * 1.Mandatory parameters are left unspecified; 796 * 2.Incorrect parameter types; 797 * @throws { BusinessError } 10200003 - Worker initialization failed. 798 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 799 * @throws { BusinessError } 10200025 - The task to be added to SequenceRunner has dependent tasks. 800 * @syscap SystemCapability.Utils.Lang 801 * @crossplatform 802 * @atomicservice 803 * @since 11 804 */ 805 /** 806 * Execute a concurrent function. 807 * 808 * @param { Task } task - The task want to execute. 809 * @returns { Promise<Object> } 810 * @throws { BusinessError } 401 - Parameter error. Possible causes: 811 * <br>1. Mandatory parameters are left unspecified; 812 * <br>2. Incorrect parameter types; 813 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 814 * @throws { BusinessError } 10200025 - dependent task not allowed. 815 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 816 * @syscap SystemCapability.Utils.Lang 817 * @crossplatform 818 * @atomicservice 819 * @since 12 820 */ 821 /** 822 * Execute a concurrent function. 823 * 824 * @param { Task } task - The task want to execute. 825 * @returns { Promise<Object> } 826 * @throws { BusinessError } 401 - Parameter error. Possible causes: 827 * <br>1. Mandatory parameters are left unspecified; 828 * <br>2. Incorrect parameter types; 829 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 830 * @throws { BusinessError } 10200025 - dependent task not allowed. 831 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 832 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 833 * @syscap SystemCapability.Utils.Lang 834 * @crossplatform 835 * @atomicservice 836 * @since 18 837 */ 838 execute(task: Task): Promise<Object>; 839 } 840 841 /** 842 * The LongTask class provides an interface to create a task that has no upper limit on execution time. 843 * 844 * @extends Task 845 * @syscap SystemCapability.Utils.Lang 846 * @crossplatform 847 * @atomicservice 848 * @since 12 849 */ 850 class LongTask extends Task { 851 } 852 853 /** 854 * The GenericsTask class provides an interface to create a task with generics. 855 * 856 * @extends Task 857 * @syscap SystemCapability.Utils.Lang 858 * @atomicservice 859 * @since 13 860 */ 861 /** 862 * The GenericsTask class provides an interface to create a task with generics. 863 * 864 * @extends Task 865 * @syscap SystemCapability.Utils.Lang 866 * @crossplatform 867 * @atomicservice 868 * @since 18 869 */ 870 class GenericsTask<A extends Array<Object>, R> extends Task { 871 /** 872 * Create a GenericsTask instance. 873 * 874 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 875 * @param { A } args - The concurrent function arguments. 876 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 877 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 878 * @syscap SystemCapability.Utils.Lang 879 * @atomicservice 880 * @since 13 881 */ 882 /** 883 * Create a GenericsTask instance. 884 * 885 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 886 * @param { A } args - The concurrent function arguments. 887 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 888 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 889 * @syscap SystemCapability.Utils.Lang 890 * @crossplatform 891 * @atomicservice 892 * @since 18 893 */ 894 constructor(func: (...args: A) => R | Promise<R>, ...args: A); 895 896 /** 897 * Create a GenericsTask instance. 898 * 899 * @param { string } name - The name of GenericsTask. 900 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 901 * @param { A } args - The concurrent function arguments. 902 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 903 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 904 * @syscap SystemCapability.Utils.Lang 905 * @atomicservice 906 * @since 13 907 */ 908 /** 909 * Create a GenericsTask instance. 910 * 911 * @param { string } name - The name of GenericsTask. 912 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 913 * @param { A } args - The concurrent function arguments. 914 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 915 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 916 * @syscap SystemCapability.Utils.Lang 917 * @crossplatform 918 * @atomicservice 919 * @since 18 920 */ 921 constructor(name: string, func: (...args: A) => R | Promise<R>, ...args: A); 922 } 923 924 /** 925 * The State defines the task state. 926 * 927 * @enum { number } State 928 * @syscap SystemCapability.Utils.Lang 929 * @crossplatform 930 * @since 10 931 */ 932 /** 933 * The State defines the task state. 934 * 935 * @enum { number } State 936 * @syscap SystemCapability.Utils.Lang 937 * @crossplatform 938 * @atomicservice 939 * @since 11 940 */ 941 enum State { 942 /** 943 * the task state is waiting. 944 * 945 * @syscap SystemCapability.Utils.Lang 946 * @crossplatform 947 * @since 10 948 */ 949 /** 950 * the task state is waiting. 951 * 952 * @syscap SystemCapability.Utils.Lang 953 * @crossplatform 954 * @atomicservice 955 * @since 11 956 */ 957 WAITING = 1, 958 959 /** 960 * the task state is running. 961 * 962 * @syscap SystemCapability.Utils.Lang 963 * @crossplatform 964 * @since 10 965 */ 966 /** 967 * the task state is running. 968 * 969 * @syscap SystemCapability.Utils.Lang 970 * @crossplatform 971 * @atomicservice 972 * @since 11 973 */ 974 RUNNING = 2, 975 976 /** 977 * the task state is canceled. 978 * 979 * @syscap SystemCapability.Utils.Lang 980 * @crossplatform 981 * @since 10 982 */ 983 /** 984 * the task state is canceled. 985 * 986 * @syscap SystemCapability.Utils.Lang 987 * @crossplatform 988 * @atomicservice 989 * @since 11 990 */ 991 CANCELED = 3 992 } 993 994 /** 995 * Indicates the internal information of the worker thread. 996 * 997 * @syscap SystemCapability.Utils.Lang 998 * @crossplatform 999 * @since 10 1000 */ 1001 /** 1002 * Indicates the internal information of the worker thread. 1003 * 1004 * @syscap SystemCapability.Utils.Lang 1005 * @crossplatform 1006 * @atomicservice 1007 * @since 11 1008 */ 1009 class TaskInfo { 1010 /** 1011 * Task identity. 1012 * 1013 * @type { number } 1014 * @default 0 1015 * @syscap SystemCapability.Utils.Lang 1016 * @crossplatform 1017 * @since 10 1018 */ 1019 /** 1020 * Task identity. 1021 * 1022 * @type { number } 1023 * @default 0 1024 * @syscap SystemCapability.Utils.Lang 1025 * @crossplatform 1026 * @atomicservice 1027 * @since 11 1028 */ 1029 taskId: number; 1030 1031 /** 1032 * Task state. 1033 * 1034 * @type { State } 1035 * @default State::WAITING 1036 * @syscap SystemCapability.Utils.Lang 1037 * @crossplatform 1038 * @since 10 1039 */ 1040 /** 1041 * Task state. 1042 * 1043 * @type { State } 1044 * @default State::WAITING 1045 * @syscap SystemCapability.Utils.Lang 1046 * @crossplatform 1047 * @atomicservice 1048 * @since 11 1049 */ 1050 state: State; 1051 1052 /** 1053 * Duration of task execution. 1054 * 1055 * @type { ?number } 1056 * @syscap SystemCapability.Utils.Lang 1057 * @crossplatform 1058 * @since 10 1059 */ 1060 /** 1061 * Duration of task execution. 1062 * 1063 * @type { ?number } 1064 * @syscap SystemCapability.Utils.Lang 1065 * @crossplatform 1066 * @atomicservice 1067 * @since 11 1068 */ 1069 duration?: number; 1070 1071 /** 1072 * Task name. 1073 * 1074 * @type { string } 1075 * @syscap SystemCapability.Utils.Lang 1076 * @crossplatform 1077 * @atomicservice 1078 * @since 12 1079 */ 1080 name: string; 1081 } 1082 1083 /** 1084 * Indicates the internal information of the worker thread. 1085 * 1086 * @syscap SystemCapability.Utils.Lang 1087 * @crossplatform 1088 * @since 10 1089 */ 1090 /** 1091 * Indicates the internal information of the worker thread. 1092 * 1093 * @syscap SystemCapability.Utils.Lang 1094 * @crossplatform 1095 * @atomicservice 1096 * @since 11 1097 */ 1098 class ThreadInfo { 1099 /** 1100 * Thread id. 1101 * 1102 * @type { number } 1103 * @default 0 1104 * @syscap SystemCapability.Utils.Lang 1105 * @crossplatform 1106 * @since 10 1107 */ 1108 /** 1109 * Thread id. 1110 * 1111 * @type { number } 1112 * @default 0 1113 * @syscap SystemCapability.Utils.Lang 1114 * @crossplatform 1115 * @atomicservice 1116 * @since 11 1117 */ 1118 tid: number; 1119 1120 /** 1121 * Task id list that running on current thread. 1122 * 1123 * @type { ?number[] } 1124 * @syscap SystemCapability.Utils.Lang 1125 * @crossplatform 1126 * @since 10 1127 */ 1128 /** 1129 * Task id list that running on current thread. 1130 * 1131 * @type { ?number[] } 1132 * @syscap SystemCapability.Utils.Lang 1133 * @crossplatform 1134 * @atomicservice 1135 * @since 11 1136 */ 1137 taskIds?: number[]; 1138 1139 /** 1140 * Thread priority. 1141 * 1142 * @type { ?Priority } 1143 * @syscap SystemCapability.Utils.Lang 1144 * @crossplatform 1145 * @since 10 1146 */ 1147 /** 1148 * Thread priority. 1149 * 1150 * @type { ?Priority } 1151 * @syscap SystemCapability.Utils.Lang 1152 * @crossplatform 1153 * @atomicservice 1154 * @since 11 1155 */ 1156 priority?: Priority; 1157 } 1158 1159 /** 1160 * Indicates the internal information of the taskpool. 1161 * 1162 * @syscap SystemCapability.Utils.Lang 1163 * @crossplatform 1164 * @since 10 1165 */ 1166 /** 1167 * Indicates the internal information of the taskpool. 1168 * 1169 * @syscap SystemCapability.Utils.Lang 1170 * @crossplatform 1171 * @atomicservice 1172 * @since 11 1173 */ 1174 class TaskPoolInfo { 1175 /** 1176 * An array of taskpool thread information. 1177 * 1178 * @type { ThreadInfo[] } 1179 * @syscap SystemCapability.Utils.Lang 1180 * @crossplatform 1181 * @since 10 1182 */ 1183 /** 1184 * An array of taskpool thread information. 1185 * 1186 * @type { ThreadInfo[] } 1187 * @syscap SystemCapability.Utils.Lang 1188 * @crossplatform 1189 * @atomicservice 1190 * @since 11 1191 */ 1192 threadInfos: ThreadInfo[]; 1193 1194 /** 1195 * An array of taskpool task information. 1196 * 1197 * @type { TaskInfo[] } 1198 * @syscap SystemCapability.Utils.Lang 1199 * @crossplatform 1200 * @since 10 1201 */ 1202 /** 1203 * An array of taskpool task information. 1204 * 1205 * @type { TaskInfo[] } 1206 * @syscap SystemCapability.Utils.Lang 1207 * @crossplatform 1208 * @atomicservice 1209 * @since 11 1210 */ 1211 taskInfos: TaskInfo[]; 1212 } 1213 1214 /** 1215 * Execute a concurrent function. 1216 * 1217 * @param { Function } func - func func Concurrent function want to execute. 1218 * @param { unknown[] } args - args args The concurrent function arguments. 1219 * @returns { Promise<unknown> } 1220 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1221 * 1.Mandatory parameters are left unspecified; 1222 * 2.Incorrect parameter types; 1223 * 3.Parameter verification failed. 1224 * @throws { BusinessError } 10200003 - Worker initialization failed. 1225 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1226 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1227 * @syscap SystemCapability.Utils.Lang 1228 * @since 9 1229 */ 1230 /** 1231 * Execute a concurrent function. 1232 * 1233 * @param { Function } func - func func Concurrent function want to execute. 1234 * @param { unknown[] } args - args args The concurrent function arguments. 1235 * @returns { Promise<unknown> } 1236 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1237 * 1.Mandatory parameters are left unspecified; 1238 * 2.Incorrect parameter types; 1239 * 3.Parameter verification failed. 1240 * @throws { BusinessError } 10200003 - Worker initialization failed. 1241 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1242 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1243 * @syscap SystemCapability.Utils.Lang 1244 * @crossplatform 1245 * @since 10 1246 */ 1247 /** 1248 * Execute a concurrent function. 1249 * 1250 * @param { Function } func - func func Concurrent function want to execute. 1251 * @param { Object[] } args - args args The concurrent function arguments. 1252 * @returns { Promise<Object> } 1253 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1254 * 1.Mandatory parameters are left unspecified; 1255 * 2.Incorrect parameter types; 1256 * 3.Parameter verification failed. 1257 * @throws { BusinessError } 10200003 - Worker initialization failed. 1258 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1259 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1260 * @syscap SystemCapability.Utils.Lang 1261 * @crossplatform 1262 * @atomicservice 1263 * @since 11 1264 */ 1265 /** 1266 * Execute a concurrent function. 1267 * 1268 * @param { Function } func - func func Concurrent function want to execute. 1269 * @param { Object[] } args - args args The concurrent function arguments. 1270 * @returns { Promise<Object> } 1271 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1272 * 1.Mandatory parameters are left unspecified; 1273 * 2.Incorrect parameter types; 1274 * 3.Parameter verification failed. 1275 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1276 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1277 * @syscap SystemCapability.Utils.Lang 1278 * @crossplatform 1279 * @atomicservice 1280 * @since 12 1281 */ 1282 function execute(func: Function, ...args: Object[]): Promise<Object>; 1283 1284 /** 1285 * Execute a concurrent function with generics. 1286 * 1287 * @param { (...args: A) => R | Promise<R> } func - Concurrent function want to execute. 1288 * @param { A } args - The concurrent function arguments. 1289 * @returns { Promise<R> } 1290 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1291 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1292 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1293 * @syscap SystemCapability.Utils.Lang 1294 * @atomicservice 1295 * @since 13 1296 */ 1297 /** 1298 * Execute a concurrent function with generics. 1299 * 1300 * @param { (...args: A) => R | Promise<R> } func - Concurrent function want to execute. 1301 * @param { A } args - The concurrent function arguments. 1302 * @returns { Promise<R> } 1303 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1304 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1305 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1306 * @syscap SystemCapability.Utils.Lang 1307 * @crossplatform 1308 * @atomicservice 1309 * @since 18 1310 */ 1311 function execute<A extends Array<Object>, R>(func: (...args: A) => R | Promise<R>, ...args: A): Promise<R>; 1312 1313 /** 1314 * Execute a concurrent task. 1315 * 1316 * @param { Task } task - task task The task want to execute. 1317 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1318 * @returns { Promise<unknown> } 1319 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1320 * 1.Mandatory parameters are left unspecified; 1321 * 2.Incorrect parameter types; 1322 * 3.Parameter verification failed. 1323 * @throws { BusinessError } 10200003 - Worker initialization failed. 1324 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1325 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1326 * @syscap SystemCapability.Utils.Lang 1327 * @since 9 1328 */ 1329 /** 1330 * Execute a concurrent task. 1331 * 1332 * @param { Task } task - task task The task want to execute. 1333 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1334 * @returns { Promise<unknown> } 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 } 10200003 - Worker initialization failed. 1340 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1341 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1342 * @syscap SystemCapability.Utils.Lang 1343 * @crossplatform 1344 * @since 10 1345 */ 1346 /** 1347 * Execute a concurrent task. 1348 * 1349 * @param { Task } task - task task The task want to execute. 1350 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1351 * @returns { Promise<Object> } 1352 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1353 * 1.Mandatory parameters are left unspecified; 1354 * 2.Incorrect parameter types; 1355 * 3.Parameter verification failed. 1356 * @throws { BusinessError } 10200003 - Worker initialization failed. 1357 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1358 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1359 * @syscap SystemCapability.Utils.Lang 1360 * @crossplatform 1361 * @atomicservice 1362 * @since 11 1363 */ 1364 /** 1365 * Execute a concurrent task. 1366 * 1367 * @param { Task } task - The task want to execute. 1368 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1369 * @returns { Promise<Object> } 1370 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1371 * <br>1. Mandatory parameters are left unspecified; 1372 * <br>2. Incorrect parameter types; 1373 * <br>3. Parameter verification failed. 1374 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1375 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1376 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1377 * @syscap SystemCapability.Utils.Lang 1378 * @crossplatform 1379 * @atomicservice 1380 * @since 12 1381 */ 1382 /** 1383 * Execute a concurrent task. 1384 * 1385 * @param { Task } task - The task want to execute. 1386 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1387 * @returns { Promise<Object> } 1388 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1389 * <br>1. Mandatory parameters are left unspecified; 1390 * <br>2. Incorrect parameter types; 1391 * <br>3. Parameter verification failed. 1392 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1393 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1394 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1395 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1396 * @syscap SystemCapability.Utils.Lang 1397 * @crossplatform 1398 * @atomicservice 1399 * @since 18 1400 */ 1401 function execute(task: Task, priority?: Priority): Promise<Object>; 1402 1403 /** 1404 * Execute a concurrent task with generics. 1405 * 1406 * @param { GenericsTask<A, R> } task - The task want to execute. 1407 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1408 * @returns { Promise<R> } 1409 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1410 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1411 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1412 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1413 * @syscap SystemCapability.Utils.Lang 1414 * @atomicservice 1415 * @since 13 1416 */ 1417 /** 1418 * Execute a concurrent task with generics. 1419 * 1420 * @param { GenericsTask<A, R> } task - The task want to execute. 1421 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1422 * @returns { Promise<R> } 1423 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1424 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1425 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1426 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1427 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1428 * @syscap SystemCapability.Utils.Lang 1429 * @crossplatform 1430 * @atomicservice 1431 * @since 18 1432 */ 1433 function execute<A extends Array<Object>, R>(task: GenericsTask<A, R>, priority?: Priority): Promise<R>; 1434 1435 /** 1436 * Execute a concurrent task group. 1437 * 1438 * @param { TaskGroup } group - group group The task group want to execute. 1439 * @param { Priority } [priority] - priority priority Task group priority, MEDIUM is default. 1440 * @returns { Promise<unknown[]> } 1441 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1442 * 1.Mandatory parameters are left unspecified; 1443 * 2.Incorrect parameter types; 1444 * 3.Parameter verification failed. 1445 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1446 * @syscap SystemCapability.Utils.Lang 1447 * @crossplatform 1448 * @since 10 1449 */ 1450 /** 1451 * Execute a concurrent task group. 1452 * 1453 * @param { TaskGroup } group - group group The task group want to execute. 1454 * @param { Priority } [priority] - priority priority Task group priority, MEDIUM is default. 1455 * @returns { Promise<Object[]> } 1456 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1457 * 1.Mandatory parameters are left unspecified; 1458 * 2.Incorrect parameter types; 1459 * 3.Parameter verification failed. 1460 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1461 * @syscap SystemCapability.Utils.Lang 1462 * @crossplatform 1463 * @atomicservice 1464 * @since 11 1465 */ 1466 function execute(group: TaskGroup, priority?: Priority): Promise<Object[]>; 1467 1468 /** 1469 * Execute a concurrent task after the specified time. 1470 * 1471 * @param { number } delayTime - delayTime delayTime The time want to delay. 1472 * @param { Task } task - task task The task want to execute. 1473 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1474 * @returns { Promise<Object> } 1475 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1476 * 1.Mandatory parameters are left unspecified; 1477 * 2.Incorrect parameter types; 1478 * 3.Parameter verification failed. 1479 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1480 * @syscap SystemCapability.Utils.Lang 1481 * @crossplatform 1482 * @atomicservice 1483 * @since 11 1484 */ 1485 /** 1486 * Execute a concurrent task after the specified time. 1487 * 1488 * @param { number } delayTime - The time want to delay. 1489 * @param { Task } task - The task want to execute. 1490 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1491 * @returns { Promise<Object> } 1492 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1493 * <br>1. Mandatory parameters are left unspecified; 1494 * <br>2. Incorrect parameter types; 1495 * <br>3. Parameter verification failed. 1496 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1497 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1498 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1499 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1500 * @syscap SystemCapability.Utils.Lang 1501 * @crossplatform 1502 * @atomicservice 1503 * @since 12 1504 */ 1505 /** 1506 * Execute a concurrent task after the specified time. 1507 * 1508 * @param { number } delayTime - The time want to delay. 1509 * @param { Task } task - The task want to execute. 1510 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1511 * @returns { Promise<Object> } 1512 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1513 * <br>1. Mandatory parameters are left unspecified; 1514 * <br>2. Incorrect parameter types; 1515 * <br>3. Parameter verification failed. 1516 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1517 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1518 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1519 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1520 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1521 * @syscap SystemCapability.Utils.Lang 1522 * @crossplatform 1523 * @atomicservice 1524 * @since 18 1525 */ 1526 function executeDelayed(delayTime: number, task: Task, priority?: Priority): Promise<Object>; 1527 1528 /** 1529 * Execute a concurrent task with generics after the specified time. 1530 * 1531 * @param { number } delayTime - The time want to delay. 1532 * @param { GenericsTask<A, R> } task - The task want to execute. 1533 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1534 * @returns { Promise<R> } 1535 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1536 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1537 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1538 * @syscap SystemCapability.Utils.Lang 1539 * @atomicservice 1540 * @since 13 1541 */ 1542 /** 1543 * Execute a concurrent task with generics after the specified time. 1544 * 1545 * @param { number } delayTime - The time want to delay. 1546 * @param { GenericsTask<A, R> } task - The task want to execute. 1547 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1548 * @returns { Promise<R> } 1549 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1550 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1551 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1552 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1553 * @syscap SystemCapability.Utils.Lang 1554 * @crossplatform 1555 * @atomicservice 1556 * @since 18 1557 */ 1558 function executeDelayed<A extends Array<Object>, R>(delayTime: number, task: GenericsTask<A, R>, priority?: Priority): Promise<R>; 1559 1560 /** 1561 * Execute a concurrent task periodically. 1562 * 1563 * @param { number } period - The period in milliseconds for executing task. 1564 * @param { Task } task - The task want to execute. 1565 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1566 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1567 * <br>1. Mandatory parameters are left unspecified; 1568 * <br>2. Incorrect parameter types; 1569 * <br>3. Parameter verification failed. 1570 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1571 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1572 * @throws { BusinessError } 10200028 - The period is less than zero. 1573 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1574 * @syscap SystemCapability.Utils.Lang 1575 * @crossplatform 1576 * @atomicservice 1577 * @since 12 1578 */ 1579 /** 1580 * Execute a concurrent task periodically. 1581 * 1582 * @param { number } period - The period in milliseconds for executing task. 1583 * @param { Task } task - The task want to execute. 1584 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1585 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1586 * <br>1. Mandatory parameters are left unspecified; 1587 * <br>2. Incorrect parameter types; 1588 * <br>3. Parameter verification failed. 1589 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1590 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1591 * @throws { BusinessError } 10200028 - The period is less than zero. 1592 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1593 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1594 * @syscap SystemCapability.Utils.Lang 1595 * @crossplatform 1596 * @atomicservice 1597 * @since 18 1598 */ 1599 function executePeriodically(period: number, task: Task, priority?: Priority): void; 1600 1601 /** 1602 * Execute a concurrent task with generics periodically. 1603 * 1604 * @param { number } period - The period in milliseconds for executing task. 1605 * @param { GenericsTask<A, R> } task - The task want to execute. 1606 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1607 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1608 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1609 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1610 * @throws { BusinessError } 10200028 - The period is less than zero. 1611 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1612 * @syscap SystemCapability.Utils.Lang 1613 * @atomicservice 1614 * @since 13 1615 */ 1616 /** 1617 * Execute a concurrent task with generics periodically. 1618 * 1619 * @param { number } period - The period in milliseconds for executing task. 1620 * @param { GenericsTask<A, R> } task - The task want to execute. 1621 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1622 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1623 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1624 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1625 * @throws { BusinessError } 10200028 - The period is less than zero. 1626 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1627 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1628 * @syscap SystemCapability.Utils.Lang 1629 * @crossplatform 1630 * @atomicservice 1631 * @since 18 1632 */ 1633 function executePeriodically<A extends Array<Object>, R>(period: number, task: GenericsTask<A, R>, priority?: Priority): void; 1634 1635 /** 1636 * Cancel a concurrent task. 1637 * 1638 * @param { Task } task - task task The task want to cancel. 1639 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1640 * 1.Mandatory parameters are left unspecified; 1641 * 2.Incorrect parameter types; 1642 * 3.Parameter verification failed. 1643 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1644 * @throws { BusinessError } 10200016 - The task to cancel is being executed. 1645 * @syscap SystemCapability.Utils.Lang 1646 * @since 9 1647 */ 1648 /** 1649 * Cancel a concurrent task. 1650 * 1651 * @param { Task } task - task task The task want to cancel. 1652 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1653 * 1.Mandatory parameters are left unspecified; 1654 * 2.Incorrect parameter types; 1655 * 3.Parameter verification failed. 1656 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1657 * @syscap SystemCapability.Utils.Lang 1658 * @crossplatform 1659 * @since 10 1660 */ 1661 /** 1662 * Cancel a concurrent task. 1663 * 1664 * @param { Task } task - task task The task want to cancel. 1665 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1666 * 1.Mandatory parameters are left unspecified; 1667 * 2.Incorrect parameter types; 1668 * 3.Parameter verification failed. 1669 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1670 * @syscap SystemCapability.Utils.Lang 1671 * @crossplatform 1672 * @atomicservice 1673 * @since 11 1674 */ 1675 /** 1676 * Cancel a concurrent task. 1677 * 1678 * @param { Task } task - task task The task want to cancel. 1679 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1680 * @throws { BusinessError } 10200055 - The asyncRunner task has been canceled. 1681 * @syscap SystemCapability.Utils.Lang 1682 * @crossplatform 1683 * @atomicservice 1684 * @since 18 1685 */ 1686 function cancel(task: Task): void; 1687 1688 /** 1689 * Cancel a concurrent task group. 1690 * 1691 * @param { TaskGroup } group - group group The task group want to cancel. 1692 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1693 * 1.Mandatory parameters are left unspecified; 1694 * 2.Incorrect parameter types; 1695 * 3.Parameter verification failed. 1696 * @throws { BusinessError } 10200018 - The task group to cancel does not exist. 1697 * @syscap SystemCapability.Utils.Lang 1698 * @crossplatform 1699 * @since 10 1700 */ 1701 /** 1702 * Cancel a concurrent task group. 1703 * 1704 * @param { TaskGroup } group - group group The task group want to cancel. 1705 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1706 * 1.Mandatory parameters are left unspecified; 1707 * 2.Incorrect parameter types; 1708 * 3.Parameter verification failed. 1709 * @throws { BusinessError } 10200018 - The task group to cancel does not exist. 1710 * @syscap SystemCapability.Utils.Lang 1711 * @crossplatform 1712 * @atomicservice 1713 * @since 11 1714 */ 1715 function cancel(group: TaskGroup): void; 1716 1717 /** 1718 * Cancel a concurrent task. 1719 * 1720 * @param { number } taskId - The task want to cancel. 1721 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1722 * @throws { BusinessError } 10200055 - The asyncRunner task has been canceled. 1723 * @syscap SystemCapability.Utils.Lang 1724 * @atomicservice 1725 * @since 18 1726 */ 1727 function cancel(taskId: number): void; 1728 1729 /** 1730 * Get task pool internal information. 1731 * 1732 * @returns { TaskPoolInfo } 1733 * @syscap SystemCapability.Utils.Lang 1734 * @crossplatform 1735 * @since 10 1736 */ 1737 /** 1738 * Get task pool internal information. 1739 * 1740 * @returns { TaskPoolInfo } 1741 * @syscap SystemCapability.Utils.Lang 1742 * @crossplatform 1743 * @atomicservice 1744 * @since 11 1745 */ 1746 function getTaskPoolInfo(): TaskPoolInfo; 1747 1748 /** 1749 * Terminate a long task. 1750 * 1751 * @param { LongTask } longTask - The long task want to terminate. 1752 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1753 * 1.Mandatory parameters are left unspecified; 1754 * 2.Incorrect parameter types; 1755 * 3.Parameter verification failed. 1756 * @syscap SystemCapability.Utils.Lang 1757 * @crossplatform 1758 * @atomicservice 1759 * @since 12 1760 */ 1761 function terminateTask(longTask: LongTask): void; 1762 1763 /** 1764 * Check if the function is a concurrent function. 1765 * 1766 * @param { Function } func - The function name to check. 1767 * @returns { boolean } Returns {@code true} if it is a concurrent function; returns {@code false} otherwise. 1768 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1769 * 1.Mandatory parameters are left unspecified; 1770 * 2.Incorrect parameter types; 1771 * 3.Parameter verification failed. 1772 * @syscap SystemCapability.Utils.Lang 1773 * @crossplatform 1774 * @atomicservice 1775 * @since 12 1776 */ 1777 function isConcurrent(func: Function): boolean; 1778 1779 /** 1780 * The AsyncRunner class provides an interface to create an async runner. 1781 * 1782 * @syscap SystemCapability.Utils.Lang 1783 * @atomicservice 1784 * @since 18 1785 */ 1786 export class AsyncRunner { 1787 /** 1788 * Create a AsyncRunner instance. 1789 * 1790 * @param { number } runningCapacity - The maximum task execution capacity. 1791 * @param { ?number } waitingCapacity - The waiting task capacity, 0 is default, means no limit on waiting task capacity. 1792 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 1793 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 1794 * @syscap SystemCapability.Utils.Lang 1795 * @atomicservice 1796 * @since 18 1797 */ 1798 constructor(runningCapacity: number, waitingCapacity?: number); 1799 1800 /** 1801 * Create or get a AsyncRunner instance by name. 1802 * 1803 * @param { string } name - AsyncRunner name, if name is the same, will return the same asyncRunner. 1804 * @param { number } runningCapacity - The maximum task execution capacity. 1805 * @param { ?number } waitingCapacity - The waiting task capacity, 0 is default, means no limit on waiting task capacity. 1806 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 1807 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 1808 * @syscap SystemCapability.Utils.Lang 1809 * @atomicservice 1810 * @since 18 1811 */ 1812 constructor(name: string, runningCapacity: number, waitingCapacity?: number); 1813 1814 /** 1815 * Execute a concurrent function. 1816 * 1817 * @param { Task } task - The task want to execute. 1818 * @param { ?Priority } priority - Task execution priority, MEDIUM is default. 1819 * @returns { Promise<Object> } 1820 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1821 * @throws { BusinessError } 10200025 - dependent task not allowed. 1822 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1823 * @throws { BusinessError } 10200054 - The asyncRunner task is discarded. 1824 * @throws { BusinessError } 10200057 - The task cannot be executed by two APIs. 1825 * @syscap SystemCapability.Utils.Lang 1826 * @atomicservice 1827 * @since 18 1828 */ 1829 execute(task: Task, priority?: Priority): Promise<Object>; 1830 } 1831} 1832 1833export default taskpool; 1834