()
| 515 | this.#reader = reader |
| 516 | } |
| 517 | get reader() { |
| 518 | if (this.#reader) { |
| 519 | return this.#reader |
| 520 | } |
| 521 | if (!this.streamUrl) { |
| 522 | throw new Error("The task has no stream Url defined.") |
| 523 | } |
| 524 | this.#reader = Task.getReader(this.streamUrl) |
| 525 | const task = this |
| 526 | const onNext = this.#reader.onNext |
| 527 | this.#reader.onNext = function ({ done, value }) { |
| 528 | if (value && typeof value === "object") { |
| 529 | if ( |
| 530 | task.status === TaskStatus.init || |
| 531 | task.status === TaskStatus.pending || |
| 532 | task.status === TaskStatus.waiting |
| 533 | ) { |
| 534 | task._setStatus(TaskStatus.processing) |
| 535 | } |
| 536 | if ("step" in value && "total_steps" in value) { |
| 537 | task.step = value.step |
| 538 | task.total_steps = value.total_steps |
| 539 | } |
| 540 | } |
| 541 | return onNext.call(this, { done, value }) |
| 542 | } |
| 543 | this.#reader.onComplete = function (value) { |
| 544 | task.result = value |
| 545 | if (task.isPending) { |
| 546 | task._setStatus(TaskStatus.completed) |
| 547 | } |
| 548 | return value |
| 549 | } |
| 550 | this.#reader.onError = function (response) { |
| 551 | const err = new Error(response.statusText) |
| 552 | task.abort(err) |
| 553 | throw err |
| 554 | } |
| 555 | return this.#reader |
| 556 | } |
| 557 | |
| 558 | async waitUntil({ timeout = -1, callback, status, signal }) { |
| 559 | const currentIdx = TASK_STATUS_ORDER.indexOf(this.#status) |
nothing calls this directly
no test coverage detected