({ timeout = -1, callback, status, signal })
| 556 | } |
| 557 | |
| 558 | async waitUntil({ timeout = -1, callback, status, signal }) { |
| 559 | const currentIdx = TASK_STATUS_ORDER.indexOf(this.#status) |
| 560 | if (currentIdx <= 0) { |
| 561 | return false |
| 562 | } |
| 563 | const stIdx = status ? TASK_STATUS_ORDER.indexOf(status) : currentIdx + 1 |
| 564 | if (stIdx >= 0 && stIdx <= currentIdx) { |
| 565 | return true |
| 566 | } |
| 567 | if (stIdx < 0 && currentIdx < 0) { |
| 568 | return this.#status === (status || TaskStatus.completed) |
| 569 | } |
| 570 | if (signal?.aborted) { |
| 571 | return false |
| 572 | } |
| 573 | const task = this |
| 574 | switch (this.#status) { |
| 575 | case TaskStatus.pending: |
| 576 | case TaskStatus.waiting: |
| 577 | // Wait for server status to include this task. |
| 578 | await waitUntil( |
| 579 | async () => { |
| 580 | if ( |
| 581 | task.#id && |
| 582 | typeof serverState.tasks === "object" && |
| 583 | Object.keys(serverState.tasks).includes(String(task.#id)) |
| 584 | ) { |
| 585 | return true |
| 586 | } |
| 587 | if ((await Promise.resolve(callback?.call(task))) || signal?.aborted) { |
| 588 | return true |
| 589 | } |
| 590 | }, |
| 591 | TASK_STATE_SERVER_UPDATE_DELAY, |
| 592 | timeout |
| 593 | ) |
| 594 | if ( |
| 595 | this.#id && |
| 596 | typeof serverState.tasks === "object" && |
| 597 | Object.keys(serverState.tasks).includes(String(task.#id)) |
| 598 | ) { |
| 599 | this._setStatus(TaskStatus.waiting) |
| 600 | } |
| 601 | if ((await Promise.resolve(callback?.call(this))) || signal?.aborted) { |
| 602 | return false |
| 603 | } |
| 604 | if (stIdx >= 0 && stIdx <= TASK_STATUS_ORDER.indexOf(TaskStatus.waiting)) { |
| 605 | return true |
| 606 | } |
| 607 | // Wait for task to start on server. |
| 608 | await waitUntil( |
| 609 | async () => { |
| 610 | if ( |
| 611 | typeof serverState.tasks !== "object" || |
| 612 | serverState.tasks[String(task.#id)] !== "pending" |
| 613 | ) { |
| 614 | return true |
| 615 | } |
no test coverage detected