(
client: Client,
request: Request<Rpcs>,
stream:
| Stream.Stream<any, any>
| Effect.Effect<Queue.Dequeue<any, any>, any, Scope.Scope>
)
| 394 | } |
| 395 | |
| 396 | const streamEffect = ( |
| 397 | client: Client, |
| 398 | request: Request<Rpcs>, |
| 399 | stream: |
| 400 | | Stream.Stream<any, any> |
| 401 | | Effect.Effect<Queue.Dequeue<any, any>, any, Scope.Scope> |
| 402 | ) => { |
| 403 | let latch = client.latches.get(request.id) |
| 404 | if (supportsAck && !latch) { |
| 405 | latch = Latch.makeUnsafe(false) |
| 406 | client.latches.set(request.id, latch) |
| 407 | } |
| 408 | if (Effect.isEffect(stream)) { |
| 409 | return stream.pipe( |
| 410 | Effect.flatMap((queue) => |
| 411 | Effect.whileLoop({ |
| 412 | while: constTrue, |
| 413 | body: constant( |
| 414 | Effect.flatMap(Queue.takeAll(queue), (values) => { |
| 415 | const write = options.onFromServer({ |
| 416 | _tag: "Chunk", |
| 417 | clientId: client.id, |
| 418 | requestId: request.id, |
| 419 | values |
| 420 | }) |
| 421 | if (!latch) return write |
| 422 | latch.closeUnsafe() |
| 423 | return Effect.flatMap(write, () => latch.await) |
| 424 | }) |
| 425 | ), |
| 426 | step: constVoid |
| 427 | }) |
| 428 | ), |
| 429 | Pull.catchDone(() => Effect.void), |
| 430 | Effect.scoped |
| 431 | ) |
| 432 | } |
| 433 | return Stream.runForEachArray(stream, (values) => { |
| 434 | const write = options.onFromServer({ |
| 435 | _tag: "Chunk", |
| 436 | clientId: client.id, |
| 437 | requestId: request.id, |
| 438 | values |
| 439 | }) |
| 440 | if (!latch) return write |
| 441 | latch.closeUnsafe() |
| 442 | return Effect.andThen(write, latch.await) |
| 443 | }) |
| 444 | } |
| 445 | |
| 446 | const sendDefect = (client: Client, defect: unknown) => |
| 447 | Effect.suspend(() => { |
no test coverage detected