(
rpc: Rpc.AnyWithProps,
middleware: (request: Request<Rpcs>) => Effect.Effect<Request<Rpcs>>,
span: Span | undefined,
payload: any,
headers: Headers.Headers,
context: Context.Context<never>,
discard: boolean
)
| 328 | } |
| 329 | |
| 330 | const onEffectRequest = ( |
| 331 | rpc: Rpc.AnyWithProps, |
| 332 | middleware: (request: Request<Rpcs>) => Effect.Effect<Request<Rpcs>>, |
| 333 | span: Span | undefined, |
| 334 | payload: any, |
| 335 | headers: Headers.Headers, |
| 336 | context: Context.Context<never>, |
| 337 | discard: boolean |
| 338 | ) => |
| 339 | Effect.withFiberRuntime<any, any, any>((parentFiber) => { |
| 340 | if (isShutdown) { |
| 341 | return Effect.interrupt |
| 342 | } |
| 343 | const id = generateRequestId() |
| 344 | const send = middleware({ |
| 345 | _tag: "Request", |
| 346 | id, |
| 347 | tag: rpc._tag as Rpc.Tag<Rpcs>, |
| 348 | payload, |
| 349 | traceId: span?.traceId, |
| 350 | spanId: span?.spanId, |
| 351 | sampled: span?.sampled, |
| 352 | headers: Headers.merge(parentFiber.getFiberRef(currentHeaders), headers) |
| 353 | }) |
| 354 | if (discard) { |
| 355 | return Effect.flatMap(send, (message) => |
| 356 | options.onFromClient({ |
| 357 | message, |
| 358 | context, |
| 359 | discard |
| 360 | })) |
| 361 | } |
| 362 | const runtime = Runtime.make({ |
| 363 | context: parentFiber.currentContext, |
| 364 | fiberRefs: parentFiber.getFiberRefs(), |
| 365 | runtimeFlags: Runtime.defaultRuntime.runtimeFlags |
| 366 | }) |
| 367 | let fiber: Fiber.RuntimeFiber<any, any> |
| 368 | let completed = false |
| 369 | return Effect.onInterrupt( |
| 370 | Effect.async<any, any>((resume) => { |
| 371 | const entry: ClientEntry = { |
| 372 | _tag: "Effect", |
| 373 | rpc, |
| 374 | context, |
| 375 | resume(exit) { |
| 376 | completed = true |
| 377 | resume(exit) |
| 378 | if (fiber && !fiber.unsafePoll()) { |
| 379 | parentFiber.currentScheduler.scheduleTask( |
| 380 | () => { |
| 381 | fiber.unsafeInterruptAsFork(parentFiber.id()) |
| 382 | }, |
| 383 | 0, |
| 384 | fiber |
| 385 | ) |
| 386 | } |
| 387 | } |
no test coverage detected