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

Function onFromClient

packages/effect/src/rpc/RpcClient.ts:692–746  ·  view source on GitHub ↗
({ message })

Source from the content-addressed store, hash-verified

690 ...options,
691 supportsAck,
692 onFromClient({ message }) {
693 switch (message._tag) {
694 case "Request": {
695 const rpc = group.requests.get(message.tag)! as any as Rpc.AnyWithProps
696 const collector = supportsTransferables ? Transferable.makeCollectorUnsafe() : undefined
697
698 const fiber = Fiber.getCurrent()!
699
700 const entry: ClientEntry = {
701 rpc,
702 context: collector ? Context.add(fiber.context, Transferable.Collector, collector) : fiber.context,
703 schemas: rpcSchemas(rpc),
704 discard: message.discard === true
705 }
706 entries.set(message.id, entry)
707
708 return entry.schemas.encodePayload(message.payload).pipe(
709 Effect.provideContext(entry.context),
710 Effect.orDie,
711 Effect.flatMap((payload) => {
712 // Checked after encoding, which can suspend while the client
713 // starts shutting down.
714 if (Deferred.isDoneUnsafe(closing)) {
715 entries.delete(message.id)
716 return Effect.interrupt
717 }
718 return send(clientId, {
719 ...message,
720 id: message.id,
721 payload,
722 headers: Object.entries(message.headers)
723 }, collector && collector.readUnsafe())
724 }),
725 // An interrupted request keeps its entry until the interrupt is sent.
726 Effect.onError((cause) =>
727 Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.sync(() => entries.delete(message.id))
728 )
729 ) as Effect.Effect<void, RpcClientError>
730 }
731 case "Ack": {
732 const entry = entries.get(message.requestId)
733 if (!entry) return Effect.void
734 return send(clientId, {
735 _tag: "Ack",
736 requestId: message.requestId
737 }) as Effect.Effect<void, RpcClientError>
738 }
739 case "Interrupt": {
740 return interruptRequest(message.requestId)
741 }
742 case "Eof": {
743 return Effect.void
744 }
745 }
746 }
747 })
748
749 yield* run(clientId, (message) => {

Callers

nothing calls this directly

Calls 9

interruptRequestFunction · 0.85
onErrorMethod · 0.80
sendFunction · 0.70
getMethod · 0.65
addMethod · 0.65
setMethod · 0.65
pipeMethod · 0.65
deleteMethod · 0.65
syncMethod · 0.45

Tested by

no test coverage detected