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

Function sendLocal

packages/effect/src/unstable/cluster/Sharding.ts:1000–1027  ·  view source on GitHub ↗
(message: M)

Source from the content-addressed store, hash-verified

998 // --- Sending messages ---
999
1000 const sendLocal = <M extends Message.Outgoing<any> | Message.Incoming<any>>(message: M) =>
1001 Effect.suspend(function loop(): Effect.Effect<
1002 void,
1003 | EntityNotAssignedToRunner
1004 | MailboxFull
1005 | AlreadyProcessingMessage
1006 | (M extends Message.Incoming<any> ? never : PersistenceError)
1007 > {
1008 const address = message.envelope.address
1009 if (!isEntityOnLocalShards(address)) {
1010 return Effect.fail(new EntityNotAssignedToRunner({ address }))
1011 }
1012 const state = entityManagers.get(address.entityType)
1013 if (!state) {
1014 return Effect.flatMap(waitForEntityManager(address.entityType), loop)
1015 } else if (state.status === "closed" || (state.status === "closing" && message._tag === "IncomingRequest")) {
1016 // if we are shutting down, we don't accept new requests
1017 return Effect.fail(new EntityNotAssignedToRunner({ address }))
1018 }
1019
1020 return message._tag === "IncomingRequest" || message._tag === "IncomingEnvelope" ?
1021 state.manager.send(message) :
1022 runnersService.sendLocal({
1023 message,
1024 send: state.manager.sendLocal,
1025 simulateRemoteSerialization: config.simulateRemoteSerialization
1026 }) as any
1027 })
1028
1029 type PendingNotification = {
1030 resume: (_: Effect.Effect<void, EntityNotAssignedToRunner>) => void

Callers 1

sendOutgoingFunction · 0.70

Calls 5

isEntityOnLocalShardsFunction · 0.85
waitForEntityManagerFunction · 0.85
sendMethod · 0.80
getMethod · 0.65
failMethod · 0.45

Tested by

no test coverage detected