| 95 | ): Channel.Channel<InElem, InElem, InErr, InErr, InDone, InDone> => |
| 96 | core.suspend(() => { |
| 97 | const doBuffer = <InErr, InElem, InDone>( |
| 98 | empty: InElem, |
| 99 | isEmpty: Predicate<InElem>, |
| 100 | ref: Ref.Ref<InElem> |
| 101 | ): Channel.Channel<InElem, InElem, InErr, InErr, InDone, InDone> => |
| 102 | unwrap( |
| 103 | Ref.modify(ref, (inElem) => |
| 104 | isEmpty(inElem) ? |
| 105 | [ |
| 106 | core.readWith({ |
| 107 | onInput: (input: InElem) => |
| 108 | core.flatMap( |
| 109 | core.write(input), |
| 110 | () => doBuffer<InErr, InElem, InDone>(empty, isEmpty, ref) |
| 111 | ), |
| 112 | onFailure: (error: InErr) => core.fail(error), |
| 113 | onDone: (done: InDone) => core.succeedNow(done) |
| 114 | }), |
| 115 | inElem |
| 116 | ] as const : |
| 117 | [ |
| 118 | core.flatMap( |
| 119 | core.write(inElem), |
| 120 | () => doBuffer<InErr, InElem, InDone>(empty, isEmpty, ref) |
| 121 | ), |
| 122 | empty |
| 123 | ] as const) |
| 124 | ) |
| 125 | return doBuffer(options.empty, options.isEmpty, options.ref) |
| 126 | }) |
| 127 | |