MCPcopy Index your code
hub / github.com/Effect-TS/effect / onFromClient

Function onFromClient

packages/cluster/src/Sharding.ts:1027–1115  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

1025 generateRequestId: () => RequestId(snowflakeGen.unsafeNext()),
1026 flatten: true,
1027 onFromClient(options): Effect.Effect<
1028 void,
1029 MailboxFull | AlreadyProcessingMessage | PersistenceError
1030 > {
1031 const address = Context.unsafeGet(options.context, ClientAddressTag)
1032 switch (options.message._tag) {
1033 case "Request": {
1034 const fiber = Option.getOrThrow(Fiber.getCurrentFiber())
1035 const id = Snowflake.Snowflake(options.message.id)
1036 const rpc = entity.protocol.requests.get(options.message.tag)!
1037 let respond: (reply: Reply.Reply<any>) => Effect.Effect<void>
1038 if (!options.discard) {
1039 const entry: ClientRequestEntry = {
1040 rpc: rpc as any,
1041 services: fiber.currentContext
1042 }
1043 clientRequests.set(id, entry)
1044 respond = makeClientRespond(entry, client.write)
1045 } else {
1046 respond = clientRespondDiscard
1047 }
1048 return sendOutgoing(
1049 new Message.OutgoingRequest({
1050 envelope: Envelope.makeRequest({
1051 requestId: id,
1052 address,
1053 tag: options.message.tag,
1054 payload: options.message.payload,
1055 headers: options.message.headers,
1056 traceId: options.message.traceId,
1057 spanId: options.message.spanId,
1058 sampled: options.message.sampled
1059 }),
1060 lastReceivedReply: Option.none(),
1061 rpc,
1062 context: fiber.currentContext as Context.Context<any>,
1063 respond
1064 }),
1065 options.discard
1066 )
1067 }
1068 case "Ack": {
1069 const requestId = Snowflake.Snowflake(options.message.requestId)
1070 const entry = clientRequests.get(requestId)
1071 if (!entry) return Effect.void
1072 return sendOutgoing(
1073 new Message.OutgoingEnvelope({
1074 envelope: new Envelope.AckChunk({
1075 id: snowflakeGen.unsafeNext(),
1076 address,
1077 requestId,
1078 replyId: entry.lastChunkId!
1079 }),
1080 rpc: entry.rpc
1081 }),
1082 false
1083 )
1084 }

Callers

nothing calls this directly

Calls 6

makeClientRespondFunction · 0.85
sendOutgoingFunction · 0.85
unsafeGetMethod · 0.80
forClientMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected