(
rpc: Rpc.AnyWithProps,
middleware: (
send: (request: Request<Rpcs>) => Effect.Effect<any, E>,
request: Request<Rpcs>
) => Effect.Effect<any, E>,
span: Span | undefined,
payload: any,
headers: Headers.Headers,
context: Context.Context<never>,
discard: boolean
)
| 347 | } |
| 348 | |
| 349 | const onEffectRequest = ( |
| 350 | rpc: Rpc.AnyWithProps, |
| 351 | middleware: ( |
| 352 | send: (request: Request<Rpcs>) => Effect.Effect<any, E>, |
| 353 | request: Request<Rpcs> |
| 354 | ) => Effect.Effect<any, E>, |
| 355 | span: Span | undefined, |
| 356 | payload: any, |
| 357 | headers: Headers.Headers, |
| 358 | context: Context.Context<never>, |
| 359 | discard: boolean |
| 360 | ) => |
| 361 | Effect.withFiber<any, any, any>((parentFiber) => { |
| 362 | if (isShutdown) { |
| 363 | return Effect.interrupt |
| 364 | } |
| 365 | const id = generateRequestId() |
| 366 | const send = middleware( |
| 367 | (message) => |
| 368 | options.onFromClient({ |
| 369 | message, |
| 370 | context, |
| 371 | discard |
| 372 | }), |
| 373 | { |
| 374 | _tag: "Request", |
| 375 | id, |
| 376 | tag: rpc._tag as Rpc.Tag<Rpcs>, |
| 377 | payload, |
| 378 | ...(span ? |
| 379 | { |
| 380 | traceId: span.traceId, |
| 381 | spanId: span.spanId, |
| 382 | sampled: span.sampled |
| 383 | } : |
| 384 | {}), |
| 385 | headers: Headers.merge(parentFiber.getRef(CurrentHeaders), headers) |
| 386 | } |
| 387 | ) |
| 388 | if (discard) { |
| 389 | return send |
| 390 | } |
| 391 | let fiber: Fiber.Fiber<any, any> |
| 392 | return Effect.onInterrupt( |
| 393 | Effect.callback<any, any>((resume) => { |
| 394 | const entry: ClientEntry = { |
| 395 | _tag: "Effect", |
| 396 | rpc, |
| 397 | context, |
| 398 | resume(exit) { |
| 399 | resume(exit) |
| 400 | if (fiber && !fiber.pollUnsafe()) { |
| 401 | parentFiber.currentDispatcher.scheduleTask(() => { |
| 402 | fiber.interruptUnsafe(parentFiber.id) |
| 403 | }, 0) |
| 404 | } |
| 405 | } |
| 406 | } |
no test coverage detected