MCPcopy Index your code
hub / github.com/easydiffusion/easydiffusion / waitUntil

Method waitUntil

ui/media/js/engine.js:558–654  ·  view source on GitHub ↗
({ timeout = -1, callback, status, signal })

Source from the content-addressed store, hash-verified

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 }

Callers 4

enqueueMethod · 0.95
startMethod · 0.80
startMethod · 0.80
jasmineSpec.jsFile · 0.80

Calls 2

_setStatusMethod · 0.95
waitUntilFunction · 0.85

Tested by

no test coverage detected