()
| 137 | // Let Node finish auto-destruction before attempting another write. |
| 138 | const onFinish = () => dispatcher.scheduleTask(loop, 0) |
| 139 | const loop = () => { |
| 140 | options.writable.off("drain", loop) |
| 141 | options.writable.off("finish", onFinish) |
| 142 | for (; i < chunk.length;) { |
| 143 | if (cancelled) { |
| 144 | return |
| 145 | } |
| 146 | const success = options.writable.write(chunk[i++], options.encoding as any, (error) => { |
| 147 | if (!error) return |
| 148 | if (options.writable.closed) { |
| 149 | // Closed streams can reject writes through the callback only; |
| 150 | // there is no pending destruction to wait for. |
| 151 | onError(error) |
| 152 | } else { |
| 153 | // Let Node initiate auto-destruction before failure cleanup |
| 154 | // checks whether an error event is still pending. |
| 155 | dispatcher.scheduleTask(() => onError(error), 0) |
| 156 | } |
| 157 | }) |
| 158 | if (!success) { |
| 159 | if (!cancelled) { |
| 160 | options.writable.once("drain", loop) |
| 161 | // A normally finished writable will never emit drain. Resume |
| 162 | // the loop so any remaining writes can report their errors. |
| 163 | options.writable.once("finish", onFinish) |
| 164 | } |
| 165 | return |
| 166 | } |
| 167 | } |
| 168 | if (!cancelled) { |
| 169 | resume(Effect.void) |
| 170 | } |
| 171 | } |
| 172 | loop() |
| 173 | return Effect.sync(() => { |
| 174 | cancelled = true |
no test coverage detected