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

Method open

ui/media/js/engine.js:87–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85 return this.open()
86 }
87 async *open() {
88 let value = undefined
89 let done = undefined
90 do {
91 if (this.#response) {
92 await asyncDelay(RETRY_DELAY_IF_BUFFER_IS_EMPTY)
93 }
94 this.#response = await fetch(this.#url, this.#fetchOptions)
95 if (!this.#response.ok) {
96 if (this.#response.status === 425) {
97 continue
98 }
99 // Request status indicate failure
100 console.warn("Stream %o stopped unexpectedly.", this.#response)
101 value = await Promise.resolve(this.onError(this.#response))
102 if (typeof value === "boolean" && value) {
103 continue
104 }
105 return value
106 }
107 const reader = this.#response.body.getReader()
108 done = false
109 do {
110 const readState = await reader.read()
111 value = this.parse(readState.value)
112 if (value) {
113 for (let sVal of value) {
114 ; ({ value: sVal, done } = await Promise.resolve(
115 this.onNext({ value: sVal, done: readState.done })
116 ))
117 yield sVal
118 if (done) {
119 return this.onComplete(sVal)
120 }
121 }
122 }
123 if (done) {
124 return
125 }
126 } while (value && !done)
127 } while (!done && (this.#response.ok || this.#response.status === 425))
128 }
129 *readStreamAsJSON(jsonStr, throwOnError) {
130 if (typeof jsonStr !== "string") {
131 throw new Error("jsonStr is not a string.")

Callers 14

startMethod · 0.80
startMethod · 0.80
pnFunction · 0.80
cFunction · 0.80
dFunction · 0.80
openDBFunction · 0.80
open_browserFunction · 0.80
update_or_download_fileFunction · 0.80

Calls 6

onErrorMethod · 0.95
parseMethod · 0.95
onNextMethod · 0.95
onCompleteMethod · 0.95
asyncDelayFunction · 0.85
getReaderMethod · 0.80

Tested by

no test coverage detected