let to_stream_fun tr en =
let rec loop_until_ready tr en =
match next tr with
| `output o -> Some o
| `end_of_stream -> None
| `not_ready ->
begin match Stream.next en with
| None -> stop tr; loop_until_ready tr en
| Some s ->
feed tr s;
loop_until_ready tr en
end
in
Stream.from (fun _ -> loop_until_ready tr en)