( make: () => Machine<In, Out> )
| 923 | } |
| 924 | |
| 925 | const makeChannel = <In, Out, IE, Done>( |
| 926 | make: () => Machine<In, Out> |
| 927 | ): Channel.Channel< |
| 928 | Arr.NonEmptyReadonlyArray<Out>, |
| 929 | XmlError | IE, |
| 930 | Done, |
| 931 | Arr.NonEmptyReadonlyArray<In>, |
| 932 | IE, |
| 933 | Done |
| 934 | > => |
| 935 | Channel.fromTransform((upstream: Pull.Pull<Arr.NonEmptyReadonlyArray<In>, IE, Done>, _scope) => |
| 936 | Effect.sync(() => { |
| 937 | const machine = make() |
| 938 | let done: Pull.Pull<never, never, Done> | undefined |
| 939 | let failure: XmlError | undefined |
| 940 | |
| 941 | // Output completed before an error is emitted before the failure |
| 942 | const emit = ( |
| 943 | inputs: ReadonlyArray<In> | undefined |
| 944 | ): Pull.Pull<Arr.NonEmptyReadonlyArray<Out>, XmlError | IE, Done> => { |
| 945 | try { |
| 946 | if (inputs === undefined) machine.end() |
| 947 | else for (let i = 0; i < inputs.length; i++) machine.push(inputs[i]) |
| 948 | } catch (error) { |
| 949 | if (!isXmlError(error)) throw error |
| 950 | failure = error |
| 951 | } |
| 952 | const out = machine.out |
| 953 | if (Arr.isArrayNonEmpty(out)) { |
| 954 | machine.out = [] |
| 955 | return Effect.succeed(out) |
| 956 | } |
| 957 | return pull |
| 958 | } |
| 959 | |
| 960 | const step = Pull.matchEffect(upstream, { |
| 961 | onSuccess: emit, |
| 962 | onFailure: Effect.failCause, |
| 963 | onDone: (value) => { |
| 964 | done = Cause.done(value) |
| 965 | return emit(undefined) |
| 966 | } |
| 967 | }) |
| 968 | const pull: Pull.Pull<Arr.NonEmptyReadonlyArray<Out>, XmlError | IE, Done> = Effect.suspend(() => |
| 969 | failure !== undefined ? Effect.fail(failure) : done ?? step |
| 970 | ) |
| 971 | return pull |
| 972 | }) |
| 973 | ) |
| 974 | |
| 975 | const makeParser = (options: DecodeOptions | undefined, bytes: boolean): () => Parser => { |
| 976 | const maxTokenSize = checkLimit("maxTokenSize", options?.maxTokenSize, defaultMaxTokenSize) |
no test coverage detected