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

Function read

packages/effect/src/internal/channel/channelExecutor.ts:1024–1091  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1022): Effect.Effect<A, E2, R> => {
1023 const readStack = [r as ChannelState.Read]
1024 const read = (): Effect.Effect<A, E2, R> => {
1025 const current = readStack.pop()
1026 if (current === undefined || current.upstream === undefined) {
1027 return Effect.dieMessage("Unexpected end of input for channel execution")
1028 }
1029 const state = current.upstream.run() as ChannelState.Primitive
1030 switch (state._tag) {
1031 case ChannelStateOpCodes.OP_EMIT: {
1032 const emitEffect = current.onEmit(current.upstream.getEmit())
1033 if (readStack.length === 0) {
1034 if (emitEffect === undefined) {
1035 return Effect.suspend(onSuccess)
1036 }
1037 return pipe(
1038 emitEffect as Effect.Effect<void>,
1039 Effect.matchCauseEffect({ onFailure, onSuccess })
1040 )
1041 }
1042 if (emitEffect === undefined) {
1043 return Effect.suspend(() => read())
1044 }
1045 return pipe(
1046 emitEffect as Effect.Effect<void>,
1047 Effect.matchCauseEffect({ onFailure, onSuccess: () => read() })
1048 )
1049 }
1050
1051 case ChannelStateOpCodes.OP_DONE: {
1052 const doneEffect = current.onDone(current.upstream.getDone())
1053 if (readStack.length === 0) {
1054 if (doneEffect === undefined) {
1055 return Effect.suspend(onSuccess)
1056 }
1057 return pipe(
1058 doneEffect as Effect.Effect<void>,
1059 Effect.matchCauseEffect({ onFailure, onSuccess })
1060 )
1061 }
1062 if (doneEffect === undefined) {
1063 return Effect.suspend(() => read())
1064 }
1065 return pipe(
1066 doneEffect as Effect.Effect<void>,
1067 Effect.matchCauseEffect({ onFailure, onSuccess: () => read() })
1068 )
1069 }
1070
1071 case ChannelStateOpCodes.OP_FROM_EFFECT: {
1072 readStack.push(current)
1073 return pipe(
1074 current.onEffect(state.effect as Effect.Effect<void>) as Effect.Effect<void>,
1075 Effect.catchAllCause((cause) =>
1076 Effect.suspend(() => {
1077 const doneEffect = current.onDone(Exit.failCause(cause)) as Effect.Effect<void>
1078 return doneEffect === undefined ? Effect.void : doneEffect
1079 })
1080 ),
1081 Effect.matchCauseEffect({ onFailure, onSuccess: () => read() })

Callers 1

readUpstreamFunction · 0.70

Calls 7

getEmitMethod · 0.80
getDoneMethod · 0.80
failCauseMethod · 0.80
dieMessageMethod · 0.65
onEffectMethod · 0.65
pipeFunction · 0.50
runMethod · 0.45

Tested by

no test coverage detected