MCPcopy Create free account
hub / github.com/Effect-TS/effect / onRequest

Function onRequest

packages/effect/src/unstable/rpc/RpcClient.ts:307–347  ·  view source on GitHub ↗
(rpc: Rpc.AnyWithProps)

Source from the content-addressed store, hash-verified

305 })
306
307 const onRequest = (rpc: Rpc.AnyWithProps) => {
308 const isStream = RpcSchema.isStreamSchema(rpc.successSchema)
309 const middleware = getRpcClientMiddleware(rpc)
310 return (payload: any, opts?: {
311 readonly asQueue?: boolean | undefined
312 readonly streamBufferSize?: number | undefined
313 readonly headers?: Headers.Input | undefined
314 readonly context?: Context.Context<never> | undefined
315 readonly discard?: boolean | undefined
316 }) => {
317 const headers = opts?.headers ? Headers.fromInput(opts.headers) : Headers.empty
318 const context = opts?.context ?? Context.empty()
319 if (!isStream) {
320 const onRequest = (span: Span | undefined) =>
321 onEffectRequest(
322 rpc,
323 middleware,
324 span,
325 rpc.payloadSchema.make(payload),
326 headers,
327 context,
328 opts?.discard ?? false
329 )
330 return disableTracing ? onRequest(undefined) : Effect.useSpan(
331 `${spanPrefix}.${rpc._tag}`,
332 { attributes: options.spanAttributes },
333 onRequest
334 )
335 }
336 const queue = onStreamRequest(
337 rpc,
338 middleware,
339 rpc.payloadSchema.make(payload),
340 headers,
341 opts?.streamBufferSize ?? 16,
342 context
343 )
344 if (opts?.asQueue) return queue
345 return Stream.unwrap(Effect.map(queue, Stream.fromQueue))
346 }
347 }
348
349 const onEffectRequest = (
350 rpc: Rpc.AnyWithProps,

Callers 2

sendFunction · 0.85
RpcClient.tsFile · 0.85

Calls 4

getRpcClientMiddlewareFunction · 0.85
onEffectRequestFunction · 0.85
makeMethod · 0.65
mapMethod · 0.45

Tested by 1

sendFunction · 0.68