let make_result ?name ~feed ~next () =
let stopped = ref false in
let one_error_has_occured = ref false in
make_general ?name ()
~feed:(fun x ->
if not !stopped then
feed x
else
raise (Feeding_stopped_transform Option.(value ~default:"" name)))
~next:(fun () ->
if !one_error_has_occured
then `end_of_stream
else
begin match next !stopped with
| `output (Error _) as e -> one_error_has_occured := true; e
| other -> other
end)
~stop:(fun () -> stopped := true)