MCPcopy Index your code
hub / github.com/anomalyco/opencode / drain

Function drain

packages/opencode/src/cli/cmd/run/runtime.queue.ts:113–266  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

111 }
112
113 const drain = () => {
114 if (draining || state.closed || state.queue.length === 0) {
115 return
116 }
117
118 draining = (async () => {
119 try {
120 while (!state.closed && state.queue.length > 0) {
121 const prompt = state.queue.shift()
122 if (!prompt) {
123 continue
124 }
125
126 const queued = state.queued.find((item) => item.prompt === prompt)
127 if (queued) removeLocalQueued(queued)
128
129 if (prompt.mode !== "shell" && isNewCommand(prompt.text)) {
130 syncQueue()
131 if (!input.onNewSession) {
132 emit(
133 {
134 type: "stream.patch",
135 patch: {
136 status: "new sessions unavailable",
137 },
138 },
139 {
140 status: "new sessions unavailable",
141 },
142 )
143 continue
144 }
145
146 emit(
147 {
148 type: "stream.patch",
149 patch: {
150 phase: "running",
151 status: "starting new session",
152 queue: state.queue.length,
153 },
154 },
155 {
156 phase: "running",
157 status: "starting new session",
158 queue: state.queue.length,
159 },
160 )
161 await input.onNewSession()
162 continue
163 }
164
165 const sent =
166 prompt.mode === "shell"
167 ? prompt
168 : {
169 ...prompt,
170 messageID: prompt.messageID ?? queued?.messageID ?? MessageID.ascending(),

Callers 1

submitFunction · 0.70

Calls 12

isNewCommandFunction · 0.90
removeLocalQueuedFunction · 0.85
syncQueueFunction · 0.85
idleMethod · 0.80
writeMethod · 0.80
emitFunction · 0.70
finishFunction · 0.70
findMethod · 0.65
appendMethod · 0.45
runMethod · 0.45
abortMethod · 0.45
rejectMethod · 0.45

Tested by

no test coverage detected