MCPcopy
hub / github.com/Effect-TS/effect / onFromServer

Function onFromServer

packages/cluster/src/internal/entityManager.ts:176–267  ·  view source on GitHub ↗
(response)

Source from the content-addressed store, hash-verified

174 concurrency: options.concurrency ?? 1,
175 disableFatalDefects: options.disableFatalDefects,
176 onFromServer(response): Effect.Effect<void> {
177 switch (response._tag) {
178 case "Exit": {
179 const request = activeRequests.get(response.requestId)
180 if (!request) return Effect.void
181
182 request.sentReply = true
183
184 // For durable messages, ignore interrupts during shutdown.
185 // They will be retried when the entity is restarted.
186 // Also, if the request is uninterruptible, we ignore the
187 // interrupt.
188 if (
189 storageEnabled &&
190 Context.get(request.rpc.annotations, Persisted) &&
191 Exit.isFailure(response.exit) &&
192 Exit.isInterrupted(response.exit) &&
193 (isShuttingDown || Uninterruptible.forServer(request.rpc.annotations))
194 ) {
195 if (!isShuttingDown) {
196 return server.write(0, {
197 ...request.message.envelope,
198 id: RequestId(request.message.envelope.requestId),
199 tag: request.message.envelope.tag as any,
200 payload: new Request({
201 ...request.message.envelope,
202 lastSentChunk: request.lastSentChunk
203 } as any) as any
204 }).pipe(
205 Effect.forkIn(scope)
206 )
207 }
208 activeRequests.delete(response.requestId)
209 return options.storage.unregisterReplyHandler(request.message.envelope.requestId)
210 }
211 return retryRespond(
212 4,
213 Effect.suspend(() =>
214 request.message.respond(
215 new Reply.WithExit({
216 requestId: Snowflake.Snowflake(response.requestId),
217 id: snowflakeGen.unsafeNext(),
218 exit: response.exit
219 })
220 )
221 )
222 ).pipe(
223 Effect.flatMap(() => {
224 processedRequestIds.add(request.message.envelope.requestId)
225 activeRequests.delete(response.requestId)
226
227 // ensure that the reaper does not remove the entity as we haven't
228 // been "idle" yet
229 if (activeRequests.size === 0) {
230 state.lastActiveCheck = clock.unsafeCurrentTimeMillis()
231 }
232
233 return Effect.void

Callers

nothing calls this directly

Calls 11

RequestIdFunction · 0.90
retryRespondFunction · 0.85
onDefectFunction · 0.85
isInterruptedMethod · 0.80
forServerMethod · 0.80
getMethod · 0.65
pipeMethod · 0.65
writeMethod · 0.65
addMethod · 0.65
dieMethod · 0.65

Tested by

no test coverage detected