(
message: Message.IncomingLocal<R>
)
| 480 | ) |
| 481 | |
| 482 | function sendLocal<R extends Rpc.Any>( |
| 483 | message: Message.IncomingLocal<R> |
| 484 | ): Effect.Effect<void, EntityNotAssignedToRunner | MailboxFull | AlreadyProcessingMessage> { |
| 485 | const draining = message._tag === "IncomingEnvelope" |
| 486 | ? drainingServers.get(message.envelope.address.entityId) |
| 487 | : undefined |
| 488 | return Effect.locally( |
| 489 | Effect.flatMap( |
| 490 | draining ? Effect.succeed(draining) : entities.get(message.envelope.address), |
| 491 | (server): Effect.Effect<void, EntityNotAssignedToRunner | MailboxFull | AlreadyProcessingMessage> => { |
| 492 | switch (message._tag) { |
| 493 | case "IncomingRequestLocal": { |
| 494 | // If the request is already running, then we might have more than |
| 495 | // one sender for the same request. In this case, the other senders |
| 496 | // should resume from storage only. |
| 497 | let entry = server.activeRequests.get(message.envelope.requestId) |
| 498 | if (entry || processedRequestIds.has(message.envelope.requestId)) { |
| 499 | return Effect.fail( |
| 500 | new AlreadyProcessingMessage({ |
| 501 | envelopeId: message.envelope.requestId, |
| 502 | address: message.envelope.address |
| 503 | }) |
| 504 | ) |
| 505 | } |
| 506 | |
| 507 | const rpc = entityRpcs.get(message.envelope.tag)! as any as Rpc.AnyWithProps |
| 508 | if (!storageEnabled && Context.get(rpc.annotations, Persisted)) { |
| 509 | return Effect.dieMessage( |
| 510 | "EntityManager.sendLocal: Cannot process a persisted message without MessageStorage" |
| 511 | ) |
| 512 | } |
| 513 | |
| 514 | // Cluster internal RPCs |
| 515 | |
| 516 | // keep-alive RPC |
| 517 | if (rpc._tag === KeepAliveRpc._tag) { |
| 518 | const msg = message as unknown as Message.IncomingRequestLocal<typeof KeepAliveRpc> |
| 519 | const reply = Effect.suspend(() => |
| 520 | Effect.orDie(retryRespond( |
| 521 | 4, |
| 522 | msg.respond( |
| 523 | new Reply.WithExit<typeof KeepAliveRpc>({ |
| 524 | requestId: message.envelope.requestId, |
| 525 | id: snowflakeGen.unsafeNext(), |
| 526 | exit: Exit.void |
| 527 | }) |
| 528 | ) |
| 529 | )) |
| 530 | ) |
| 531 | |
| 532 | if (server.keepAliveEnabled) return reply |
| 533 | server.keepAliveEnabled = true |
| 534 | return server.keepAliveLatch.whenOpen(Effect.suspend(() => { |
| 535 | server.keepAliveEnabled = false |
| 536 | return reply |
| 537 | })).pipe( |
| 538 | Effect.forkIn(server.scope), |
| 539 | Effect.asVoid |
no test coverage detected