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 addDependency(...tasks: Task[]): void; 364 365 /** 366 * Remove dependencies on the task array for this task. 367 * 368 * @param { Task[] } tasks - tasks tasks An array of dependent tasks. 369 * @throws { BusinessError } 401 - Parameter error. Possible causes: 370 * 1.Mandatory parameters are left unspecified; 371 * 2.Incorrect parameter types; 372 * 3.Parameter verification failed. 373 * @throws { BusinessError } 10200027 - The dependency does not exist. 374 * @syscap SystemCapability.Utils.Lang 375 * @crossplatform 376 * @atomicservice 377 * @since 11 378 */ 379 /** 380 * Remove dependencies on the task array for this task. 381 * 382 * @param { Task[] } tasks - An array of dependent tasks. 383 * @throws { BusinessError } 401 - Parameter error. Possible causes: 384 * <br>1. Mandatory parameters are left unspecified; 385 * <br>2. Incorrect parameter types; 386 * <br>3. Parameter verification failed. 387 * @throws { BusinessError } 10200027 - The dependency does not exist. 388 * @throws { BusinessError } 10200052 - The periodic task cannot have a dependency. 389 * @syscap SystemCapability.Utils.Lang 390 * @crossplatform 391 * @atomicservice 392 * @since 12 393 */ 394 removeDependency(...tasks: Task[]): void; 395 396 /** 397 * Register a callback and call it when the task is enqueued. 398 * 399 * @param { CallbackFunction } [callback] - Callback to be registered and executed later on the host side. 400 * @throws { BusinessError } 401 - The input parameters are invalid. 401 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 402 * @syscap SystemCapability.Utils.Lang 403 * @crossplatform 404 * @atomicservice 405 * @since 12 406 */ 407 onEnqueued(callback: CallbackFunction): void; 408 409 /** 410 * Register a callback and call it when the task before execute. 411 * 412 * @param { CallbackFunction } [callback] - Callback to be registered and executed later on the host side. 413 * @throws { BusinessError } 401 - The input parameters are invalid. 414 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 415 * @syscap SystemCapability.Utils.Lang 416 * @crossplatform 417 * @atomicservice 418 * @since 12 419 */ 420 onStartExecution(callback: CallbackFunction): void; 421 422 /** 423 * Register a callback and call it when the task fails to execute. 424 * 425 * @param { CallbackFunctionWithError } [callback] - Callback to be registered and executed later on the host side. 426 * @throws { BusinessError } 401 - The input parameters are invalid. 427 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 428 * @syscap SystemCapability.Utils.Lang 429 * @crossplatform 430 * @atomicservice 431 * @since 12 432 */ 433 onExecutionFailed(callback: CallbackFunctionWithError): void; 434 435 /** 436 * Register a callback and call it when the task successfully executes. 437 * 438 * @param { CallbackFunction } [callback] - Callback to be registered and executed later on the host side. 439 * @throws { BusinessError } 401 - The input parameters are invalid. 440 * @throws { BusinessError } 10200034 - The executed task does not support the registration of listeners. 441 * @syscap SystemCapability.Utils.Lang 442 * @crossplatform 443 * @atomicservice 444 * @since 12 445 */ 446 onExecutionSucceeded(callback: CallbackFunction): void; 447 448 /** 449 * Check if the task has been completed. 450 * 451 * @returns { boolean } Returns {@code true} if the task has been completed; returns {@code false} otherwise. 452 * @syscap SystemCapability.Utils.Lang 453 * @crossplatform 454 * @atomicservice 455 * @since 12 456 */ 457 isDone(): boolean; 458 459 /** 460 * Concurrent function to execute in taskpool. 461 * 462 * @syscap SystemCapability.Utils.Lang 463 * @since 9 464 */ 465 /** 466 * Concurrent function to execute in taskpool. 467 * 468 * @syscap SystemCapability.Utils.Lang 469 * @crossplatform 470 * @since 10 471 */ 472 /** 473 * Concurrent function to execute in taskpool. 474 * 475 * @syscap SystemCapability.Utils.Lang 476 * @crossplatform 477 * @atomicservice 478 * @since 11 479 */ 480 function: Function; 481 482 /** 483 * The concurrent function arguments. 484 * 485 * @syscap SystemCapability.Utils.Lang 486 * @since 9 487 */ 488 /** 489 * The concurrent function arguments. 490 * 491 * @type { ?unknown[] } 492 * @syscap SystemCapability.Utils.Lang 493 * @crossplatform 494 * @since 10 495 */ 496 /** 497 * The concurrent function arguments. 498 * 499 * @type { ?Object[] } 500 * @syscap SystemCapability.Utils.Lang 501 * @crossplatform 502 * @atomicservice 503 * @since 11 504 */ 505 arguments?: Object[]; 506 507 /** 508 * Task name. 509 * 510 * @syscap SystemCapability.Utils.Lang 511 * @crossplatform 512 * @atomicservice 513 * @since 11 514 */ 515 name: string; 516 517 /** 518 * Total duration of task execution. 519 * 520 * @type { number } 521 * @default 0 522 * @syscap SystemCapability.Utils.Lang 523 * @crossplatform 524 * @atomicservice 525 * @since 11 526 */ 527 totalDuration: number; 528 529 /** 530 * IO duration of task execution. 531 * 532 * @type { number } 533 * @default 0 534 * @syscap SystemCapability.Utils.Lang 535 * @crossplatform 536 * @atomicservice 537 * @since 11 538 */ 539 ioDuration: number; 540 541 /** 542 * CPU duration of task execution. 543 * 544 * @type { number } 545 * @default 0 546 * @syscap SystemCapability.Utils.Lang 547 * @crossplatform 548 * @atomicservice 549 * @since 11 550 */ 551 cpuDuration: number; 552 } 553 554 /** 555 * The TaskGroup class provides an interface to create a task group. 556 * 557 * @syscap SystemCapability.Utils.Lang 558 * @crossplatform 559 * @since 10 560 */ 561 /** 562 * The TaskGroup class provides an interface to create a task group. 563 * 564 * @syscap SystemCapability.Utils.Lang 565 * @crossplatform 566 * @atomicservice 567 * @since 11 568 */ 569 class TaskGroup { 570 /** 571 * Create a TaskGroup instance. 572 * 573 * @syscap SystemCapability.Utils.Lang 574 * @crossplatform 575 * @since 10 576 */ 577 /** 578 * Create a TaskGroup instance. 579 * 580 * @syscap SystemCapability.Utils.Lang 581 * @crossplatform 582 * @atomicservice 583 * @since 11 584 */ 585 constructor(); 586 587 /** 588 * Create a TaskGroup instance. 589 * 590 * @param { string } name - name name The name of taskGroup. 591 * @throws { BusinessError } 401 - Parameter error. Possible causes: 592 * 1.Mandatory parameters are left unspecified; 593 * 2.Incorrect parameter types; 594 * 3.Parameter verification failed. 595 * @syscap SystemCapability.Utils.Lang 596 * @crossplatform 597 * @atomicservice 598 * @since 11 599 */ 600 constructor(name: string); 601 602 /** 603 * Add a Concurrent function into task group. 604 * 605 * @param { Function } func - func func Concurrent function to add in task group. 606 * @param { unknown[] } args - args args The concurrent function arguments. 607 * @throws { BusinessError } 401 - Parameter error. Possible causes: 608 * 1.Mandatory parameters are left unspecified; 609 * 2.Incorrect parameter types; 610 * 3.Parameter verification failed. 611 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 612 * @syscap SystemCapability.Utils.Lang 613 * @crossplatform 614 * @since 10 615 */ 616 /** 617 * Add a Concurrent function into task group. 618 * 619 * @param { Function } func - func func Concurrent function to add in task group. 620 * @param { Object[] } args - args args The concurrent function arguments. 621 * @throws { BusinessError } 401 - Parameter error. Possible causes: 622 * 1.Mandatory parameters are left unspecified; 623 * 2.Incorrect parameter types; 624 * 3.Parameter verification failed. 625 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 626 * @syscap SystemCapability.Utils.Lang 627 * @crossplatform 628 * @atomicservice 629 * @since 11 630 */ 631 addTask(func: Function, ...args: Object[]): void; 632 633 /** 634 * Add a Task into TaskGroup. 635 * 636 * @param { Task } task - task task The task want to add in task group. 637 * @throws { BusinessError } 401 - Parameter error. Possible causes: 638 * 1.Mandatory parameters are left unspecified; 639 * 2.Incorrect parameter types; 640 * 3.Parameter verification failed. 641 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 642 * @syscap SystemCapability.Utils.Lang 643 * @crossplatform 644 * @since 10 645 */ 646 /** 647 * Add a Task into TaskGroup. 648 * 649 * @param { Task } task - task task The task want to add in task group. 650 * @throws { BusinessError } 401 - Parameter error. Possible causes: 651 * 1.Mandatory parameters are left unspecified; 652 * 2.Incorrect parameter types; 653 * 3.Parameter verification failed. 654 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 655 * @syscap SystemCapability.Utils.Lang 656 * @crossplatform 657 * @atomicservice 658 * @since 11 659 */ 660 /** 661 * Add a Task into TaskGroup. 662 * 663 * @param { Task } task - The task want to add in task group. 664 * @throws { BusinessError } 401 - Parameter error. Possible causes: 665 * <br>1. Mandatory parameters are left unspecified; 666 * <br>2. Incorrect parameter types; 667 * <br>3. Parameter verification failed. 668 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 669 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 670 * @syscap SystemCapability.Utils.Lang 671 * @crossplatform 672 * @atomicservice 673 * @since 12 674 */ 675 addTask(task: Task): void; 676 677 /** 678 * TaskGroup name. 679 * 680 * @syscap SystemCapability.Utils.Lang 681 * @crossplatform 682 * @atomicservice 683 * @since 11 684 */ 685 name: string; 686 } 687 688 /** 689 * The SequenceRunner class provides an interface to create a task sequence runner. 690 * 691 * @syscap SystemCapability.Utils.Lang 692 * @crossplatform 693 * @atomicservice 694 * @since 11 695 */ 696 class SequenceRunner { 697 /** 698 * Create a SequenceRunner instance. 699 * 700 * @param { Priority } priority - Task execution priority, MEDIUM is default. 701 * @throws { BusinessError } 401 - Parameter error. Possible causes: 702 * 1.Incorrect parameter types; 703 * 2.Parameter verification failed. 704 * @syscap SystemCapability.Utils.Lang 705 * @crossplatform 706 * @atomicservice 707 * @since 11 708 */ 709 constructor(priority?: Priority); 710 711 /** 712 * Create or get a SequenceRunner instance by name. 713 * 714 * @param { string } name - SequenceRunner name, if name is the same, will return the same SequenceRunner. 715 * @param { Priority } priority - Task execution priority, MEDIUM is default. 716 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 717 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 718 * @syscap SystemCapability.Utils.Lang 719 * @crossplatform 720 * @atomicservice 721 * @since 12 722 */ 723 constructor(name: string, priority?: Priority); 724 725 /** 726 * Execute a concurrent function. 727 * 728 * @param { Task } task - The task want to execute. 729 * @returns { Promise<Object> } 730 * @throws { BusinessError } 401 - Parameter error. Possible causes: 731 * 1.Mandatory parameters are left unspecified; 732 * 2.Incorrect parameter types; 733 * @throws { BusinessError } 10200003 - Worker initialization failed. 734 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 735 * @throws { BusinessError } 10200025 - The task to be added to SequenceRunner has dependent tasks. 736 * @syscap SystemCapability.Utils.Lang 737 * @crossplatform 738 * @atomicservice 739 * @since 11 740 */ 741 /** 742 * Execute a concurrent function. 743 * 744 * @param { Task } task - The task want to execute. 745 * @returns { Promise<Object> } 746 * @throws { BusinessError } 401 - Parameter error. Possible causes: 747 * <br>1. Mandatory parameters are left unspecified; 748 * <br>2. Incorrect parameter types; 749 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 750 * @throws { BusinessError } 10200025 - dependent task not allowed. 751 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 752 * @syscap SystemCapability.Utils.Lang 753 * @crossplatform 754 * @atomicservice 755 * @since 12 756 */ 757 execute(task: Task): Promise<Object>; 758 } 759 760 /** 761 * The LongTask class provides an interface to create a task that has no upper limit on execution time. 762 * 763 * @extends Task 764 * @syscap SystemCapability.Utils.Lang 765 * @crossplatform 766 * @atomicservice 767 * @since 12 768 */ 769 class LongTask extends Task { 770 } 771 772 /** 773 * The GenericsTask class provides an interface to create a task with generics. 774 * 775 * @extends Task 776 * @syscap SystemCapability.Utils.Lang 777 * @atomicservice 778 * @since 13 779 */ 780 class GenericsTask<A extends Array<Object>, R> extends Task { 781 /** 782 * Create a GenericsTask instance. 783 * 784 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 785 * @param { A } args - The concurrent function arguments. 786 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 787 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 788 * @syscap SystemCapability.Utils.Lang 789 * @atomicservice 790 * @since 13 791 */ 792 constructor(func: (...args: A) => R | Promise<R>, ...args: A); 793 794 /** 795 * Create a GenericsTask instance. 796 * 797 * @param { string } name - The name of GenericsTask. 798 * @param { (...args: A) => R | Promise<R> } func - Concurrent function to execute in taskpool. 799 * @param { A } args - The concurrent function arguments. 800 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 801 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 802 * @syscap SystemCapability.Utils.Lang 803 * @atomicservice 804 * @since 13 805 */ 806 constructor(name: string, func: (...args: A) => R | Promise<R>, ...args: A); 807 } 808 809 /** 810 * The State defines the task state. 811 * 812 * @enum { number } State 813 * @syscap SystemCapability.Utils.Lang 814 * @crossplatform 815 * @since 10 816 */ 817 /** 818 * The State defines the task state. 819 * 820 * @enum { number } State 821 * @syscap SystemCapability.Utils.Lang 822 * @crossplatform 823 * @atomicservice 824 * @since 11 825 */ 826 enum State { 827 /** 828 * the task state is waiting. 829 * 830 * @syscap SystemCapability.Utils.Lang 831 * @crossplatform 832 * @since 10 833 */ 834 /** 835 * the task state is waiting. 836 * 837 * @syscap SystemCapability.Utils.Lang 838 * @crossplatform 839 * @atomicservice 840 * @since 11 841 */ 842 WAITING = 1, 843 844 /** 845 * the task state is running. 846 * 847 * @syscap SystemCapability.Utils.Lang 848 * @crossplatform 849 * @since 10 850 */ 851 /** 852 * the task state is running. 853 * 854 * @syscap SystemCapability.Utils.Lang 855 * @crossplatform 856 * @atomicservice 857 * @since 11 858 */ 859 RUNNING = 2, 860 861 /** 862 * the task state is canceled. 863 * 864 * @syscap SystemCapability.Utils.Lang 865 * @crossplatform 866 * @since 10 867 */ 868 /** 869 * the task state is canceled. 870 * 871 * @syscap SystemCapability.Utils.Lang 872 * @crossplatform 873 * @atomicservice 874 * @since 11 875 */ 876 CANCELED = 3 877 } 878 879 /** 880 * Indicates the internal information of the worker thread. 881 * 882 * @syscap SystemCapability.Utils.Lang 883 * @crossplatform 884 * @since 10 885 */ 886 /** 887 * Indicates the internal information of the worker thread. 888 * 889 * @syscap SystemCapability.Utils.Lang 890 * @crossplatform 891 * @atomicservice 892 * @since 11 893 */ 894 class TaskInfo { 895 /** 896 * Task identity. 897 * 898 * @type { number } 899 * @default 0 900 * @syscap SystemCapability.Utils.Lang 901 * @crossplatform 902 * @since 10 903 */ 904 /** 905 * Task identity. 906 * 907 * @type { number } 908 * @default 0 909 * @syscap SystemCapability.Utils.Lang 910 * @crossplatform 911 * @atomicservice 912 * @since 11 913 */ 914 taskId: number; 915 916 /** 917 * Task state. 918 * 919 * @type { State } 920 * @default State::WAITING 921 * @syscap SystemCapability.Utils.Lang 922 * @crossplatform 923 * @since 10 924 */ 925 /** 926 * Task state. 927 * 928 * @type { State } 929 * @default State::WAITING 930 * @syscap SystemCapability.Utils.Lang 931 * @crossplatform 932 * @atomicservice 933 * @since 11 934 */ 935 state: State; 936 937 /** 938 * Duration of task execution. 939 * 940 * @type { ?number } 941 * @syscap SystemCapability.Utils.Lang 942 * @crossplatform 943 * @since 10 944 */ 945 /** 946 * Duration of task execution. 947 * 948 * @type { ?number } 949 * @syscap SystemCapability.Utils.Lang 950 * @crossplatform 951 * @atomicservice 952 * @since 11 953 */ 954 duration?: number; 955 956 /** 957 * Task name. 958 * 959 * @type { string } 960 * @syscap SystemCapability.Utils.Lang 961 * @crossplatform 962 * @atomicservice 963 * @since 12 964 */ 965 name: string; 966 } 967 968 /** 969 * Indicates the internal information of the worker thread. 970 * 971 * @syscap SystemCapability.Utils.Lang 972 * @crossplatform 973 * @since 10 974 */ 975 /** 976 * Indicates the internal information of the worker thread. 977 * 978 * @syscap SystemCapability.Utils.Lang 979 * @crossplatform 980 * @atomicservice 981 * @since 11 982 */ 983 class ThreadInfo { 984 /** 985 * Thread id. 986 * 987 * @type { number } 988 * @default 0 989 * @syscap SystemCapability.Utils.Lang 990 * @crossplatform 991 * @since 10 992 */ 993 /** 994 * Thread id. 995 * 996 * @type { number } 997 * @default 0 998 * @syscap SystemCapability.Utils.Lang 999 * @crossplatform 1000 * @atomicservice 1001 * @since 11 1002 */ 1003 tid: number; 1004 1005 /** 1006 * Task id list that running on current thread. 1007 * 1008 * @type { ?number[] } 1009 * @syscap SystemCapability.Utils.Lang 1010 * @crossplatform 1011 * @since 10 1012 */ 1013 /** 1014 * Task id list that running on current thread. 1015 * 1016 * @type { ?number[] } 1017 * @syscap SystemCapability.Utils.Lang 1018 * @crossplatform 1019 * @atomicservice 1020 * @since 11 1021 */ 1022 taskIds?: number[]; 1023 1024 /** 1025 * Thread priority. 1026 * 1027 * @type { ?Priority } 1028 * @syscap SystemCapability.Utils.Lang 1029 * @crossplatform 1030 * @since 10 1031 */ 1032 /** 1033 * Thread priority. 1034 * 1035 * @type { ?Priority } 1036 * @syscap SystemCapability.Utils.Lang 1037 * @crossplatform 1038 * @atomicservice 1039 * @since 11 1040 */ 1041 priority?: Priority; 1042 } 1043 1044 /** 1045 * Indicates the internal information of the taskpool. 1046 * 1047 * @syscap SystemCapability.Utils.Lang 1048 * @crossplatform 1049 * @since 10 1050 */ 1051 /** 1052 * Indicates the internal information of the taskpool. 1053 * 1054 * @syscap SystemCapability.Utils.Lang 1055 * @crossplatform 1056 * @atomicservice 1057 * @since 11 1058 */ 1059 class TaskPoolInfo { 1060 /** 1061 * An array of taskpool thread information. 1062 * 1063 * @type { ThreadInfo[] } 1064 * @syscap SystemCapability.Utils.Lang 1065 * @crossplatform 1066 * @since 10 1067 */ 1068 /** 1069 * An array of taskpool thread information. 1070 * 1071 * @type { ThreadInfo[] } 1072 * @syscap SystemCapability.Utils.Lang 1073 * @crossplatform 1074 * @atomicservice 1075 * @since 11 1076 */ 1077 threadInfos: ThreadInfo[]; 1078 1079 /** 1080 * An array of taskpool task information. 1081 * 1082 * @type { TaskInfo[] } 1083 * @syscap SystemCapability.Utils.Lang 1084 * @crossplatform 1085 * @since 10 1086 */ 1087 /** 1088 * An array of taskpool task information. 1089 * 1090 * @type { TaskInfo[] } 1091 * @syscap SystemCapability.Utils.Lang 1092 * @crossplatform 1093 * @atomicservice 1094 * @since 11 1095 */ 1096 taskInfos: TaskInfo[]; 1097 } 1098 1099 /** 1100 * Execute a concurrent function. 1101 * 1102 * @param { Function } func - func func Concurrent function want to execute. 1103 * @param { unknown[] } args - args args The concurrent function arguments. 1104 * @returns { Promise<unknown> } 1105 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1106 * 1.Mandatory parameters are left unspecified; 1107 * 2.Incorrect parameter types; 1108 * 3.Parameter verification failed. 1109 * @throws { BusinessError } 10200003 - Worker initialization failed. 1110 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1111 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1112 * @syscap SystemCapability.Utils.Lang 1113 * @since 9 1114 */ 1115 /** 1116 * Execute a concurrent function. 1117 * 1118 * @param { Function } func - func func Concurrent function want to execute. 1119 * @param { unknown[] } args - args args The concurrent function arguments. 1120 * @returns { Promise<unknown> } 1121 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1122 * 1.Mandatory parameters are left unspecified; 1123 * 2.Incorrect parameter types; 1124 * 3.Parameter verification failed. 1125 * @throws { BusinessError } 10200003 - Worker initialization failed. 1126 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1127 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1128 * @syscap SystemCapability.Utils.Lang 1129 * @crossplatform 1130 * @since 10 1131 */ 1132 /** 1133 * Execute a concurrent function. 1134 * 1135 * @param { Function } func - func func Concurrent function want to execute. 1136 * @param { Object[] } args - args args The concurrent function arguments. 1137 * @returns { Promise<Object> } 1138 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1139 * 1.Mandatory parameters are left unspecified; 1140 * 2.Incorrect parameter types; 1141 * 3.Parameter verification failed. 1142 * @throws { BusinessError } 10200003 - Worker initialization failed. 1143 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1144 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1145 * @syscap SystemCapability.Utils.Lang 1146 * @crossplatform 1147 * @atomicservice 1148 * @since 11 1149 */ 1150 /** 1151 * Execute a concurrent function. 1152 * 1153 * @param { Function } func - func func Concurrent function want to execute. 1154 * @param { Object[] } args - args args The concurrent function arguments. 1155 * @returns { Promise<Object> } 1156 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1157 * 1.Mandatory parameters are left unspecified; 1158 * 2.Incorrect parameter types; 1159 * 3.Parameter verification failed. 1160 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1161 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1162 * @syscap SystemCapability.Utils.Lang 1163 * @crossplatform 1164 * @atomicservice 1165 * @since 12 1166 */ 1167 function execute(func: Function, ...args: Object[]): Promise<Object>; 1168 1169 /** 1170 * Execute a concurrent function with generics. 1171 * 1172 * @param { (...args: A) => R | Promise<R> } func - Concurrent function want to execute. 1173 * @param { A } args - The concurrent function arguments. 1174 * @returns { Promise<R> } 1175 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1176 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1177 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1178 * @syscap SystemCapability.Utils.Lang 1179 * @atomicservice 1180 * @since 13 1181 */ 1182 function execute<A extends Array<Object>, R>(func: (...args: A) => R | Promise<R>, ...args: A): Promise<R>; 1183 1184 /** 1185 * Execute a concurrent task. 1186 * 1187 * @param { Task } task - task task The task want to execute. 1188 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1189 * @returns { Promise<unknown> } 1190 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1191 * 1.Mandatory parameters are left unspecified; 1192 * 2.Incorrect parameter types; 1193 * 3.Parameter verification failed. 1194 * @throws { BusinessError } 10200003 - Worker initialization failed. 1195 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1196 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1197 * @syscap SystemCapability.Utils.Lang 1198 * @since 9 1199 */ 1200 /** 1201 * Execute a concurrent task. 1202 * 1203 * @param { Task } task - task task The task want to execute. 1204 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1205 * @returns { Promise<unknown> } 1206 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1207 * 1.Mandatory parameters are left unspecified; 1208 * 2.Incorrect parameter types; 1209 * 3.Parameter verification failed. 1210 * @throws { BusinessError } 10200003 - Worker initialization failed. 1211 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1212 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1213 * @syscap SystemCapability.Utils.Lang 1214 * @crossplatform 1215 * @since 10 1216 */ 1217 /** 1218 * Execute a concurrent task. 1219 * 1220 * @param { Task } task - task task The task want to execute. 1221 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1222 * @returns { Promise<Object> } 1223 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1224 * 1.Mandatory parameters are left unspecified; 1225 * 2.Incorrect parameter types; 1226 * 3.Parameter verification failed. 1227 * @throws { BusinessError } 10200003 - Worker initialization failed. 1228 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1229 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1230 * @syscap SystemCapability.Utils.Lang 1231 * @crossplatform 1232 * @atomicservice 1233 * @since 11 1234 */ 1235 /** 1236 * Execute a concurrent task. 1237 * 1238 * @param { Task } task - The task want to execute. 1239 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1240 * @returns { Promise<Object> } 1241 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1242 * <br>1. Mandatory parameters are left unspecified; 1243 * <br>2. Incorrect parameter types; 1244 * <br>3. Parameter verification failed. 1245 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1246 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1247 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1248 * @syscap SystemCapability.Utils.Lang 1249 * @crossplatform 1250 * @atomicservice 1251 * @since 12 1252 */ 1253 function execute(task: Task, priority?: Priority): Promise<Object>; 1254 1255 /** 1256 * Execute a concurrent task with generics. 1257 * 1258 * @param { GenericsTask<A, R> } task - The task want to execute. 1259 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1260 * @returns { Promise<R> } 1261 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1262 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1263 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1264 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1265 * @syscap SystemCapability.Utils.Lang 1266 * @atomicservice 1267 * @since 13 1268 */ 1269 function execute<A extends Array<Object>, R>(task: GenericsTask<A, R>, priority?: Priority): Promise<R>; 1270 1271 /** 1272 * Execute a concurrent task group. 1273 * 1274 * @param { TaskGroup } group - group group The task group want to execute. 1275 * @param { Priority } [priority] - priority priority Task group priority, MEDIUM is default. 1276 * @returns { Promise<unknown[]> } 1277 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1278 * 1.Mandatory parameters are left unspecified; 1279 * 2.Incorrect parameter types; 1280 * 3.Parameter verification failed. 1281 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1282 * @syscap SystemCapability.Utils.Lang 1283 * @crossplatform 1284 * @since 10 1285 */ 1286 /** 1287 * Execute a concurrent task group. 1288 * 1289 * @param { TaskGroup } group - group group The task group want to execute. 1290 * @param { Priority } [priority] - priority priority Task group priority, MEDIUM is default. 1291 * @returns { Promise<Object[]> } 1292 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1293 * 1.Mandatory parameters are left unspecified; 1294 * 2.Incorrect parameter types; 1295 * 3.Parameter verification failed. 1296 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1297 * @syscap SystemCapability.Utils.Lang 1298 * @crossplatform 1299 * @atomicservice 1300 * @since 11 1301 */ 1302 function execute(group: TaskGroup, priority?: Priority): Promise<Object[]>; 1303 1304 /** 1305 * Execute a concurrent task after the specified time. 1306 * 1307 * @param { number } delayTime - delayTime delayTime The time want to delay. 1308 * @param { Task } task - task task The task want to execute. 1309 * @param { Priority } [priority] - priority priority Task priority, MEDIUM is default. 1310 * @returns { Promise<Object> } 1311 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1312 * 1.Mandatory parameters are left unspecified; 1313 * 2.Incorrect parameter types; 1314 * 3.Parameter verification failed. 1315 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1316 * @syscap SystemCapability.Utils.Lang 1317 * @crossplatform 1318 * @atomicservice 1319 * @since 11 1320 */ 1321 /** 1322 * Execute a concurrent task after the specified time. 1323 * 1324 * @param { number } delayTime - The time want to delay. 1325 * @param { Task } task - The task want to execute. 1326 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1327 * @returns { Promise<Object> } 1328 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1329 * <br>1. Mandatory parameters are left unspecified; 1330 * <br>2. Incorrect parameter types; 1331 * <br>3. Parameter verification failed. 1332 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1333 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1334 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1335 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1336 * @syscap SystemCapability.Utils.Lang 1337 * @crossplatform 1338 * @atomicservice 1339 * @since 12 1340 */ 1341 function executeDelayed(delayTime: number, task: Task, priority?: Priority): Promise<Object>; 1342 1343 /** 1344 * Execute a concurrent task with generics after the specified time. 1345 * 1346 * @param { number } delayTime - The time want to delay. 1347 * @param { GenericsTask<A, R> } task - The task want to execute. 1348 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1349 * @returns { Promise<R> } 1350 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1351 * @throws { BusinessError } 10200028 - The delayTime is less than zero. 1352 * @throws { BusinessError } 10200051 - The periodic task cannot be executed again. 1353 * @syscap SystemCapability.Utils.Lang 1354 * @atomicservice 1355 * @since 13 1356 */ 1357 function executeDelayed<A extends Array<Object>, R>(delayTime: number, task: GenericsTask<A, R>, priority?: Priority): Promise<R>; 1358 1359 /** 1360 * Execute a concurrent task periodically. 1361 * 1362 * @param { number } period - The period in milliseconds for executing task. 1363 * @param { Task } task - The task want to execute. 1364 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1365 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1366 * <br>1. Mandatory parameters are left unspecified; 1367 * <br>2. Incorrect parameter types; 1368 * <br>3. Parameter verification failed. 1369 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1370 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1371 * @throws { BusinessError } 10200028 - The period is less than zero. 1372 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1373 * @syscap SystemCapability.Utils.Lang 1374 * @crossplatform 1375 * @atomicservice 1376 * @since 12 1377 */ 1378 function executePeriodically(period: number, task: Task, priority?: Priority): void; 1379 1380 /** 1381 * Execute a concurrent task with generics periodically. 1382 * 1383 * @param { number } period - The period in milliseconds for executing task. 1384 * @param { GenericsTask<A, R> } task - The task want to execute. 1385 * @param { Priority } [priority] - Task priority, MEDIUM is default. 1386 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. 1387 * @throws { BusinessError } 10200006 - An exception occurred during serialization. 1388 * @throws { BusinessError } 10200014 - The function is not marked as concurrent. 1389 * @throws { BusinessError } 10200028 - The period is less than zero. 1390 * @throws { BusinessError } 10200050 - The concurrent task has been executed and cannot be executed periodically. 1391 * @syscap SystemCapability.Utils.Lang 1392 * @atomicservice 1393 * @since 13 1394 */ 1395 function executePeriodically<A extends Array<Object>, R>(period: number, task: GenericsTask<A, R>, priority?: Priority): void; 1396 1397 /** 1398 * Cancel a concurrent task. 1399 * 1400 * @param { Task } task - task task The task want to cancel. 1401 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1402 * 1.Mandatory parameters are left unspecified; 1403 * 2.Incorrect parameter types; 1404 * 3.Parameter verification failed. 1405 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1406 * @throws { BusinessError } 10200016 - The task to cancel is being executed. 1407 * @syscap SystemCapability.Utils.Lang 1408 * @since 9 1409 */ 1410 /** 1411 * Cancel a concurrent task. 1412 * 1413 * @param { Task } task - task task The task want to cancel. 1414 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1415 * 1.Mandatory parameters are left unspecified; 1416 * 2.Incorrect parameter types; 1417 * 3.Parameter verification failed. 1418 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1419 * @syscap SystemCapability.Utils.Lang 1420 * @crossplatform 1421 * @since 10 1422 */ 1423 /** 1424 * Cancel a concurrent task. 1425 * 1426 * @param { Task } task - task task The task want to cancel. 1427 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1428 * 1.Mandatory parameters are left unspecified; 1429 * 2.Incorrect parameter types; 1430 * 3.Parameter verification failed. 1431 * @throws { BusinessError } 10200015 - The task to cancel does not exist. 1432 * @syscap SystemCapability.Utils.Lang 1433 * @crossplatform 1434 * @atomicservice 1435 * @since 11 1436 */ 1437 function cancel(task: Task): void; 1438 1439 /** 1440 * Cancel a concurrent task group. 1441 * 1442 * @param { TaskGroup } group - group group The task group want to cancel. 1443 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1444 * 1.Mandatory parameters are left unspecified; 1445 * 2.Incorrect parameter types; 1446 * 3.Parameter verification failed. 1447 * @throws { BusinessError } 10200018 - The task group to cancel does not exist. 1448 * @syscap SystemCapability.Utils.Lang 1449 * @crossplatform 1450 * @since 10 1451 */ 1452 /** 1453 * Cancel a concurrent task group. 1454 * 1455 * @param { TaskGroup } group - group group The task group want to cancel. 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 } 10200018 - The task group to cancel does not exist. 1461 * @syscap SystemCapability.Utils.Lang 1462 * @crossplatform 1463 * @atomicservice 1464 * @since 11 1465 */ 1466 function cancel(group: TaskGroup): void; 1467 1468 /** 1469 * Get task pool internal information. 1470 * 1471 * @returns { TaskPoolInfo } 1472 * @syscap SystemCapability.Utils.Lang 1473 * @crossplatform 1474 * @since 10 1475 */ 1476 /** 1477 * Get task pool internal information. 1478 * 1479 * @returns { TaskPoolInfo } 1480 * @syscap SystemCapability.Utils.Lang 1481 * @crossplatform 1482 * @atomicservice 1483 * @since 11 1484 */ 1485 function getTaskPoolInfo(): TaskPoolInfo; 1486 1487 /** 1488 * Terminate a long task. 1489 * 1490 * @param { LongTask } longTask - The long task want to terminate. 1491 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1492 * 1.Mandatory parameters are left unspecified; 1493 * 2.Incorrect parameter types; 1494 * 3.Parameter verification failed. 1495 * @syscap SystemCapability.Utils.Lang 1496 * @crossplatform 1497 * @atomicservice 1498 * @since 12 1499 */ 1500 function terminateTask(longTask: LongTask): void; 1501 1502 /** 1503 * Check if the function is a concurrent function. 1504 * 1505 * @param { Function } func - The function name to check. 1506 * @returns { boolean } Returns {@code true} if it is a concurrent function; returns {@code false} otherwise. 1507 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1508 * 1.Mandatory parameters are left unspecified; 1509 * 2.Incorrect parameter types; 1510 * 3.Parameter verification failed. 1511 * @syscap SystemCapability.Utils.Lang 1512 * @crossplatform 1513 * @atomicservice 1514 * @since 12 1515 */ 1516 function isConcurrent(func: Function): boolean; 1517} 1518 1519export default taskpool; 1520