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

Function sendOutgoing

packages/cluster/src/Sharding.ts:1028–1066  ·  view source on GitHub ↗
(
    message: Message.Outgoing<any>,
    discard: boolean,
    retries?: number
  )

Source from the content-addressed store, hash-verified

1026 : runnersService.send({ address: runner, message })
1027
1028 function sendOutgoing(
1029 message: Message.Outgoing<any>,
1030 discard: boolean,
1031 retries?: number
1032 ): Effect.Effect<
1033 void,
1034 MailboxFull | AlreadyProcessingMessage | PersistenceError
1035 > {
1036 return Effect.catchIf(
1037 Effect.suspend(() => {
1038 const address = message.envelope.address
1039 const isPersisted = Context.get(message.rpc.annotations, Persisted)
1040 if (isPersisted && !storageEnabled) {
1041 return Effect.die("Sharding.sendOutgoing: Persisted messages require MessageStorage")
1042 }
1043 const maybeRunner = MutableHashMap.get(shardAssignments, address.shardId)
1044 const runnerIsLocal = Option.isSome(maybeRunner) && isLocalRunner(maybeRunner.value)
1045 if (isPersisted) {
1046 return runnerIsLocal
1047 ? notifyLocal(message, discard)
1048 : runnersService.notify({ address: maybeRunner, message, discard })
1049 } else if (Option.isNone(maybeRunner)) {
1050 return Effect.fail(new EntityNotAssignedToRunner({ address }))
1051 }
1052 if (message._tag === "OutgoingRequest") {
1053 const entry = clientRequests.get(message.envelope.requestId)
1054 if (entry) entry.runner = maybeRunner.value
1055 }
1056 return sendToRunner(maybeRunner.value, message)
1057 }),
1058 (error) => error._tag === "EntityNotAssignedToRunner" || error._tag === "RunnerUnavailable",
1059 (error) => {
1060 if (retries === 0) {
1061 return Effect.die(error)
1062 }
1063 return Effect.delay(sendOutgoing(message, discard, retries && retries - 1), config.sendRetryInterval)
1064 }
1065 )
1066 }
1067
1068 const reset: Sharding["Type"]["reset"] = (requestId) =>
1069 Effect.matchCause(storage.clearReplies(requestId), {

Callers 2

onFromClientFunction · 0.85
Sharding.tsFile · 0.85

Calls 6

isLocalRunnerFunction · 0.85
sendToRunnerFunction · 0.85
notifyLocalFunction · 0.70
getMethod · 0.65
dieMethod · 0.65
failMethod · 0.65

Tested by

no test coverage detected