(options)
| 1241 | generateRequestId: () => RequestId(snowflakeGen.unsafeNext()), |
| 1242 | flatten: true, |
| 1243 | onFromClient(options): Effect.Effect< |
| 1244 | void, |
| 1245 | MailboxFull | AlreadyProcessingMessage | PersistenceError |
| 1246 | > { |
| 1247 | const address = Context.unsafeGet(options.context, ClientAddressTag) |
| 1248 | switch (options.message._tag) { |
| 1249 | case "Request": { |
| 1250 | const fiber = Option.getOrThrow(Fiber.getCurrentFiber()) |
| 1251 | const id = Snowflake.Snowflake(options.message.id) |
| 1252 | const rpc = entity.protocol.requests.get(options.message.tag)! |
| 1253 | let respond: (reply: Reply.Reply<any>) => Effect.Effect<void> |
| 1254 | if (!options.discard) { |
| 1255 | const entry: ClientRequestEntry = { |
| 1256 | rpc: rpc as any, |
| 1257 | services: fiber.currentContext |
| 1258 | } |
| 1259 | clientRequests.set(id, entry) |
| 1260 | respond = makeClientRespond(entry, client.write) |
| 1261 | } else { |
| 1262 | respond = clientRespondDiscard |
| 1263 | } |
| 1264 | return sendOutgoing( |
| 1265 | new Message.OutgoingRequest({ |
| 1266 | envelope: Envelope.makeRequest({ |
| 1267 | requestId: id, |
| 1268 | address, |
| 1269 | tag: options.message.tag, |
| 1270 | payload: options.message.payload, |
| 1271 | headers: options.message.headers, |
| 1272 | traceId: options.message.traceId, |
| 1273 | spanId: options.message.spanId, |
| 1274 | sampled: options.message.sampled |
| 1275 | }), |
| 1276 | lastReceivedReply: Option.none(), |
| 1277 | rpc, |
| 1278 | context: fiber.currentContext as Context.Context<any>, |
| 1279 | respond |
| 1280 | }), |
| 1281 | options.discard |
| 1282 | ) |
| 1283 | } |
| 1284 | case "Ack": { |
| 1285 | const requestId = Snowflake.Snowflake(options.message.requestId) |
| 1286 | const entry = clientRequests.get(requestId) |
| 1287 | if (!entry) return Effect.void |
| 1288 | return sendOutgoing( |
| 1289 | new Message.OutgoingEnvelope({ |
| 1290 | envelope: new Envelope.AckChunk({ |
| 1291 | id: snowflakeGen.unsafeNext(), |
| 1292 | address, |
| 1293 | requestId, |
| 1294 | replyId: entry.lastChunkId! |
| 1295 | }), |
| 1296 | rpc: entry.rpc |
| 1297 | }), |
| 1298 | false |
| 1299 | ) |
| 1300 | } |
nothing calls this directly
no test coverage detected