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

Method start

ui/media/js/engine.js:924–1030  ·  view source on GitHub ↗
(progressCallback)

Source from the content-addressed store, hash-verified

922 return Task.enqueueNew(this, RenderTask, progressCallback)
923 }
924 *start(progressCallback) {
925 if (typeof progressCallback !== "undefined" && typeof progressCallback !== "function") {
926 throw new Error("progressCallback is not a function. progressCallback type: " + typeof progressCallback)
927 }
928 if (this.isStopped) {
929 return
930 }
931
932 this._setStatus(TaskStatus.pending)
933 progressCallback?.call(this, { reqBody: this._reqBody })
934 Object.freeze(this._reqBody)
935
936 // Post task request to backend
937 let renderRequest = undefined
938 try {
939 renderRequest = yield this.post()
940 yield progressCallback?.call(this, { renderResponse: renderRequest })
941 } catch (e) {
942 yield progressCallback?.call(this, { detail: e.message })
943 throw e
944 }
945 try {
946 // Wait for task to start on server.
947 yield this.waitUntil({
948 callback: function () {
949 return progressCallback?.call(this, {})
950 },
951 status: TaskStatus.processing,
952 })
953 } catch (e) {
954 this.abort(err)
955 throw e
956 }
957 // Update class status and callback.
958 const taskState = typeof serverState.tasks === "object" ? serverState.tasks[String(this.id)] : undefined
959 switch (taskState) {
960 case "pending": // Session has pending tasks.
961 console.error("Server %o render request %o is still waiting.", serverState, renderRequest)
962 //Only update status if not already set by waitUntil
963 if (this.status === TaskStatus.init || this.status === TaskStatus.pending) {
964 // Set status as Waiting in backend.
965 this._setStatus(TaskStatus.waiting)
966 }
967 break
968 case "running":
969 case "buffer":
970 // Normal expected messages.
971 this._setStatus(TaskStatus.processing)
972 break
973 case "completed":
974 if (this.isPending) {
975 // Set state to processing until we read the reply
976 this._setStatus(TaskStatus.processing)
977 }
978 console.warn("Server %o render request %o completed unexpectedly", serverState, renderRequest)
979 break // Continue anyway to try to read cached result.
980 case "error":
981 this._setStatus(TaskStatus.failed)

Callers 9

enqueueNewMethod · 0.45
runMethod · 0.45
startMethod · 0.45
runMethod · 0.45
continueTasksFunction · 0.45
jasmine.jsFile · 0.45
JsApiReporterFunction · 0.45
execute2_Method · 0.45

Calls 5

postMethod · 0.95
_setStatusMethod · 0.80
waitUntilMethod · 0.80
abortMethod · 0.80
openMethod · 0.80

Tested by

no test coverage detected