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

Function executeAcquire

packages/platform/src/internal/worker.ts:151–184  ·  view source on GitHub ↗
(request: I, makeMailbox: Effect.Effect<Q>)

Source from the content-addressed store, hash-verified

149 })
150
151 const executeAcquire = <
152 Q extends Mailbox.Mailbox<O, E | WorkerError> | Deferred.Deferred<O, E | WorkerError>
153 >(request: I, makeMailbox: Effect.Effect<Q>) =>
154 Effect.withFiberRuntime<{
155 readonly id: number
156 readonly mailbox: Q
157 }>((fiber) => {
158 const context = fiber.getFiberRef(FiberRef.currentContext)
159 const span = Context.getOption(context, Tracer.ParentSpan).pipe(
160 Option.filter((span): span is Tracer.Span => span._tag === "Span")
161 )
162 const id = requestIdCounter++
163 return makeMailbox.pipe(
164 Effect.tap((mailbox) => {
165 requestMap.set(id, mailbox)
166 return wrappedEncode(request).pipe(
167 Effect.tap((payload) =>
168 backing.send([
169 id,
170 0,
171 payload,
172 span._tag === "Some" ? [span.value.traceId, span.value.spanId, span.value.sampled] : undefined
173 ], collector.unsafeRead())
174 ),
175 Effect.catchAllCause((cause) =>
176 Mailbox.isMailbox<O, E | WorkerError>(mailbox)
177 ? mailbox.failCause(cause)
178 : Deferred.failCause(mailbox, cause)
179 )
180 )
181 }),
182 Effect.map((mailbox) => ({ id, mailbox }))
183 )
184 })
185
186 const executeRelease = ({ id }: { readonly id: number }, exit: Exit.Exit<unknown, unknown>) => {
187 const release = Effect.sync(() => requestMap.delete(id))

Callers 2

executeFunction · 0.85
executeEffectFunction · 0.85

Calls 6

failCauseMethod · 0.80
getFiberRefMethod · 0.65
pipeMethod · 0.65
getOptionMethod · 0.65
setMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…